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. JS--我发现,原来你是这样的JS(二)(基础概念--躯壳篇--不妨从中文角度看js)

    一.介绍 这是红宝书(JavaScript高级程序设计 3版)的读书笔记第二篇(基础概念--躯壳篇),有着部分第三章的知识内容,当然其中还有我个人的理解. 红宝书这本书可以说是难啃的,要看完不容易,挺 ...

  2. ionic开发之Android的focus起作用,而iOS不起作用

    基于ionic的iOS的hybird APP无法使用focus获取焦点和键盘的问题. 解决办法就是: 原本APP的配置文件config.xml里面默认有一句 这句话的大概意思就是键盘的显示需要用户去触 ...

  3. python基础一数据类型之列表

    摘要: python基础一中写到列表,那么这篇主要讲列表. 1,定义列表 2,列表.元祖.字符串都属于序列,都可以用用索引和切片. 3,列表的方法 1,定义列表 list1 = ['a','b',1, ...

  4. Asp.Net MVC 模型(使用Entity Framework创建模型类)

    这篇教程的目的是解释在创建ASP.NET MVC应用程序时,如何使用Microsoft Entity Framework来创建数据访问类.这篇教程假设你事先对Microsoft Entity Fram ...

  5. 检索 COM 类工厂中 CLSID 为 {00021A20-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80080005

    创建Excel对象失败: Excel.Application xApp = new Excel.Application(); 错误提示:{"检索 COM 类工厂中 CLSID 为 {0002 ...

  6. 第六次作业 orm整合 接口

    结合以前一个项目,将普通的jdbc进行了相关整合,全部改写成了hibernate接口 项目名称:短视频分享平台 主要功能:用户模块:注册.登录.编辑资料.查看用户相关 分类模块:分类添加.查看 视频共 ...

  7. vcenter server appliance(vcsa) 配置IP的方法

    方法一: vcenter server appliance 5.1 及以后版本包括5.5,在安装完毕后,console界面是没有网络配置项的,如果需要进行IP配置,可以login后,输入命令yast( ...

  8. arrayfun用法(转)

    http://blog.sina.com.cn/s/blog_7cf4f4460101bnhh.html 利用arrayfun函数可以避免无谓的循环,从而大大提高代码的简介性.1.A=ARRAYFUN ...

  9. 阿里八八Alpha阶段Scrum(6/12)

    今日进度 叶文滔: 修复了无法正确判断拖曳与点击的BUG,并且成功连接添加界面. 会议内容 会议照片 明日安排 叶文滔: 继续完善按钮功能 王国超: 继续攻克日程界面显示存在的BUG 俞鋆: 继续进行 ...

  10. 自己写的开源MVC-easyMVC分享

    简介 基本风格是按照spring mvc做的,在后期会加入一些新的特性,封装成易于自己项目使用的mvc框架. github地址: https://github.com/tangyanbo/easymv ...