void worker_DoWork(object sender, DoWorkEventArgs e)
{
isBussy = true; if (Common.isChangingAccount) {
rt = new ResultInfo() { code = 3, isSucc = false, msg = "now system change account" };
return; } if (isTest)
{ rt = new ResultInfo() { code=1, isSucc =true, msg="OK" };
if (Common.rnd.Next(1, 9) >4) {
rt.code = 3;
rt.msg = "now system change account";
changeAccount();
} System.Threading.Thread.Sleep(1000);
return;
}
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{ lbLoadStatus.Content = "" + rt.code + " " + rt.msg ;
isBussy = false;
worker = null; } void changeAccount() { Common.isChangingAccount = true; // Common.AccountList[2].status = "" + DateTime.Now;
AccountInfo acc= Common.AccountList.FirstOrDefault(n => n.account == "wgscd2");
if (acc != null) {
acc.status = "send complete";
acc.reachDailyMax = true;
}
acc = Common.AccountList.FirstOrDefault(n => n.reachDailyMax ==false && n.loginTimes < 4 );
if (acc != null)
{
acc.status = "login failed";
acc.loginTimes += 1;
// BLL.Login(acc.account,acc.pwd );
changeAccount();
}
else {
rt.msg = "all account send complete";
Common.stopFlag = true;
return;
} System.Threading.Thread.Sleep(5000);
Common.isChangingAccount = false ; } public static class Common
{
public static bool stopFlag = true;
public static bool isChangingAccount=false ;
public static Random rnd = new Random();
public static CookieContainer myCookieContainer = new CookieContainer();
public static MsgType gMsgType = MsgType.sayHi;
private static ObservableCollection <AccountInfo> _AccountList;
public static ObservableCollection <AccountInfo> AccountList{
get{
if(_AccountList==null){
_AccountList= BLL.getAccountList();
}
return _AccountList;
}
set {
_AccountList=value; }
} } public enum MsgType {
sayHi=0, chatMsg=1 } public static class AppConfigData{
/// <summary>
/// 登录用户名
/// </summary>
public static string uid;
/// <summary>
/// 登录用户密码
/// </summary>
public static string pwd;
/// <summary>
/// 发送消息内容
/// </summary>
public static string msgContent;
public static MsgType sendMsgType ; } public static class LoginUser { public static string uid { get; set; }
public static string pwd { get; set; }
public static string sex { get; set; } } public class AccountInfo:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _account;
public string account { get { return _account; } set
{
if (value != _account)
{
_account = value;
//when changed ,notice
NotifyChanged("account");
} }
} private string _pwd;
public string pwd
{ get { return _pwd; } set
{
if (value != _pwd)
{
_pwd = value;
//when changed ,notice
NotifyChanged("pwd");
} }
} private string _status;
public string status
{ get { return _status; } set
{
if (value != _status)
{
_status = value;
//when changed ,notice
NotifyChanged("status");
} }
} private bool _reachDailyMax;
public bool reachDailyMax
{ get { return _reachDailyMax; } set
{
if (value != _reachDailyMax)
{
_reachDailyMax = value;
//when changed ,notice
NotifyChanged("reachDailyMax");
} }
} private int _loginTimes;
public int loginTimes
{ get { return _loginTimes; } set
{
if (value != _loginTimes)
{
_loginTimes = value;
//when changed ,notice
NotifyChanged("loginTimes");
} }
} public void NotifyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
} }

  

Account window:

ui:

<Window x:Class="WzlyTool.AccountWind"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AccountWind" Height="293" Width="619" WindowStartupLocation="CenterScreen">
<Grid>
<ListView Name="listView" BorderThickness="0" Background="White" Margin="0,0,0,0" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="listView_SelectionChanged" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Header="account" Width="122" DisplayMemberBinding="{Binding account}"/>
<GridViewColumn Header="pws" Width="88" DisplayMemberBinding="{Binding pwd}"/>
<GridViewColumn Header="status" Width="158" DisplayMemberBinding="{Binding status}"/>
<GridViewColumn Header="try login Times" Width="128" DisplayMemberBinding="{Binding loginTimes}"/> </GridView> </ListView.View>
</ListView>
<Button Content="Button" Height="35" HorizontalAlignment="Left" Margin="314,100,0,0" Name="button1" VerticalAlignment="Top" Width="133" Click="button1_Click" />
</Grid>
</Window>

  

code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace WzlyTool
{
/// <summary>
/// Interaction logic for AccountWind.xaml
/// </summary>
public partial class AccountWind : Window
{
public AccountWind()
{
InitializeComponent();
listView.DataContext = Common.AccountList;
listView.ItemsSource = Common.AccountList;
Loaded += new RoutedEventHandler(AccountWind_Loaded);
} void AccountWind_Loaded(object sender, RoutedEventArgs e)
{
listView.ItemsSource = Common.AccountList; } ObservableCollection<AccountInfo> listData = new ObservableCollection<AccountInfo>();
private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ } private void button1_Click(object sender, RoutedEventArgs e)
{ Common.AccountList[2].status = "" + DateTime.Now; } }
}

  

then main window

 void worker_DoWork(object sender, DoWorkEventArgs e)
{ while (!Common. stopFlag)
{ System.Threading.Thread.Sleep(1000); while (Common.isChangingAccount) { System.Threading.Thread.Sleep(1000); } Dispatcher.Invoke(new Action (() => { for (int i = 0; i < 10;i++ )
{ if (Common .stopFlag) return;
UserInfo ui = new UserInfo();
myWrapPanel.Children.Add(new MailMsg(ui,true));
myScrollViewer.ScrollToEnd();
lbCnt.Content = "" + myWrapPanel.Children.Count; // if(myWrapPanel.Children[i] as
} })); } }

  

Multi account chang login with multi -thread的更多相关文章

  1. Multi Paxos

    Multi Paxos [2] 通过basic paxos 以上步骤分布式系统已经能确定一个值,“只确定一个值有什么用?这可解决不了我面临的问题.” 你心中可能有这样的疑问. 原simple paxo ...

  2. Using a Microsoft Account to Logon and Resulting Internet Communication in Windows 8

    Using a Microsoft Account to Logon and Resulting Internet Communication in Windows 8 此主题尚未评级 - 评价此主题 ...

  3. metasploit-post模块信息

    Name                                             Disclosure Date  Rank    Description ----           ...

  4. Kali linux 2016.2(Rolling)中的Exploits模块详解

    简单来将,这个Exploits模块,就是针对不同的已知漏洞的利用程序. root@kali:~# msfconsole Unable to handle kernel NULL pointer der ...

  5. leetcode bugfree note

    463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...

  6. 如何在Visual Studio中开发自己的代码生成器插件

     Visual Studio是美国微软公司开发的一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具.代码管控工具.集成开发环境(IDE)等等,且所写的目标代码适用于微 ...

  7. android asmack 注册 登陆 聊天 多人聊天室 文件传输

    XMPP协议简介 XMPP协议(Extensible Messaging and PresenceProtocol,可扩展消息处理现场协议)是一种基于XML的协议,目的是为了解决及时通信标准而提出来的 ...

  8. Jmeter_初步认识随笔

    1. 简介 Apache JMeter是100%纯java桌面应用程序,被设计用来测试客户端/服务器结构的软件(例如web应用程序).它可以用来测试包括基于静态和动态资源程序的性能,例如静态文件,Ja ...

  9. 【Android Api 翻译4】android api 完整翻译之Contacts Provider (学习安卓必知的api,中英文对照)

    Contacts Provider 电话簿(注:联系人,联络人.通信录)提供者 ------------------------------- QUICKVIEW 快速概览 * Android's r ...

随机推荐

  1. Memcached+WebApi记录

    一.安装Memcached Memcached1.2.6 http://files.cnblogs.com/files/jasonduan/11465401756756.zip Memcached.C ...

  2. Android Dragger2快速入门浅析

    定Dagger2的基本介绍:dagger2是一个依赖注入框架,在编译期间自动生成代码,负责依赖对象的创建. 使用Dagger2的好处:为了进一步解耦和方便测试,我们会使用依赖注入的方式构建对象 (不使 ...

  3. Android应用程序进程启动过程(后篇)

    前言 在前篇中我们讲到了Android应用程序进程启动过程,这一篇我们来讲遗留的知识点:在应用程序进程创建过程中会启动Binder线程池以及在应用程序进程启动后会创建消息循环. 1.Binder线程池 ...

  4. 微信为啥不能直接下载.apk安装包

    今天遇到一个很蛋疼问题,我们的微信公众号上想放一个下载自己公司app的点击按钮,如果是苹果手机点击这个按钮就直接跳转到苹果的appstore,如果是android手机的话,就直接跳我们的服务器下载ap ...

  5. Huawei华为交换机 consolep密码和vty密码配置telnet,ssh

    以登录用户界面的认证方式为密码认证,密码为Huawei@123为例,配置如下. <HUAWEI> system-view [HUAWEI] user- [HUAWEI-ui-console ...

  6. tp5多数据库配置

    1.在项目文件下建立extra文件夹,复制dadabase.php改名为database_foo.php,并将从数据库配置信息配置好,如下图: 2.调用 1)调用从数据库$data = Db::con ...

  7. saltstack二次开发(二)

    Saltstack的api Salt-api有两种方式,一种是函数的形式,有人家定义好的函数,我们可以直接调用,直接写python代码调用函数或者类就可以了.第二种形式是salt-api有封装好的ht ...

  8. js字符串String常用方法

    1.   charAt()         返回指定位置的字符. str.charAt(index) index 为必须参数,类型为number(0到str.length-1之间,否则该方法返回 空串 ...

  9. 洛谷P1208

    #include <iostream>#include <algorithm>#include <cstdio>using namespace std; struc ...

  10. Mapreduce运行过程分析(基于Hadoop2.4)——(二)

    4.3 Map类    创建Map类和map函数.map函数是org.apache.hadoop.mapreduce.Mapper类中的定义的,当处理每一个键值对的时候,都要调用一次map方法,用户须 ...