Multi account chang login with multi -thread
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的更多相关文章
- Multi Paxos
Multi Paxos [2] 通过basic paxos 以上步骤分布式系统已经能确定一个值,“只确定一个值有什么用?这可解决不了我面临的问题.” 你心中可能有这样的疑问. 原simple paxo ...
- 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 此主题尚未评级 - 评价此主题 ...
- metasploit-post模块信息
Name Disclosure Date Rank Description ---- ...
- Kali linux 2016.2(Rolling)中的Exploits模块详解
简单来将,这个Exploits模块,就是针对不同的已知漏洞的利用程序. root@kali:~# msfconsole Unable to handle kernel NULL pointer der ...
- leetcode bugfree note
463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的 ...
- 如何在Visual Studio中开发自己的代码生成器插件
Visual Studio是美国微软公司开发的一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具.代码管控工具.集成开发环境(IDE)等等,且所写的目标代码适用于微 ...
- android asmack 注册 登陆 聊天 多人聊天室 文件传输
XMPP协议简介 XMPP协议(Extensible Messaging and PresenceProtocol,可扩展消息处理现场协议)是一种基于XML的协议,目的是为了解决及时通信标准而提出来的 ...
- Jmeter_初步认识随笔
1. 简介 Apache JMeter是100%纯java桌面应用程序,被设计用来测试客户端/服务器结构的软件(例如web应用程序).它可以用来测试包括基于静态和动态资源程序的性能,例如静态文件,Ja ...
- 【Android Api 翻译4】android api 完整翻译之Contacts Provider (学习安卓必知的api,中英文对照)
Contacts Provider 电话簿(注:联系人,联络人.通信录)提供者 ------------------------------- QUICKVIEW 快速概览 * Android's r ...
随机推荐
- <Android 基础(三十四)> TabLayout 从头到脚
1. 简介 1.TabLayout给我们提供的是一排横向的标签页 2.#newTab()这个方法来创建新的标签页,然后用过#setText()和#setIcon方法分别修改标签页的文本和图标,创建完成 ...
- Randoop介绍、安装及环境变量配置
大体来说,开发人员开发源程序,测试人员找bug,中间人产品经理. 黑盒测试:(不看代码) 白盒测试: 1.基于覆盖:语句.分支(if.for.真假).方法 结构:顺序.分支(T or F,做出选择). ...
- 数据库小组与UI小组第一次对接
时间:2018.6.1,21:30 ~ 23:00 人员:除黄志鹏外全体成员,因为黄志鹏临时有事 工作内容: 主要为数据库小组与UI第二组对接,并将成果汇总到github仓库.另外UI第一组重构了代码 ...
- 03-02_配置weblogic domain
配置Domain 图形化界面: [Windows] Windows菜单 [windows] config.cmd [Unix/Linux] config.sh 命令行界面: [windows] con ...
- 【gp数据库】你一定会用到的运维语句宝典
-- 查询未空闲的进程信息 select * from pg_stat_activity where current_query<>'<IDLE>'; 结果可查看数据库名,进程 ...
- shell變量和數組
我們要知道shell是一個很重要的腳本能幫助我們完成很多事情 shell語言其實和很多的語言的語法是差不多的 變量: 變量的定義很簡單的,但是等號兩邊是不可以有空格的(不能有空格) 命名只能使用英文字 ...
- FTP 命令的使用
最近需要使用 ftp 工具,所以借此机会来进行整理以下具体的内容: 具体什么是ftp, ftp 能干什么? 请参考: https://access.redhat.com/documentation/e ...
- Linux 快速查看系统配置-熟悉新环境的配置
问题背景: 当我们使用新的环境的时候,需要很快得熟悉自己环境的配置,这时候我们如果知道一些命令就极为方便了.这样你就能对自己的环境较为熟悉,进行工作的时候也能随心所欲了. 如果你使用workstati ...
- Docker 使用入门,创建一个Nginx服务器
运行环境: MAC Docker 版本: Docker version 17.12.0-ce, build c97c6d6 一.启动Nginx 服务器 启动Nginx 服务器,并进入模拟终端 dock ...
- 自己模拟写C++中的String类型
下面是模拟实现字符串的相关功能,它包括一下功能: String(const char * s);//利用字符串来初始化对象 String(); //默认构造函数 String(con ...