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 ...
随机推荐
- 01-01基于SHELL的数据分析
#!/usr/bin/env bash for year in /root/Downloads/data/all/* do echo -ne `basename $year .gz`"\t& ...
- php用smarty来做简易留言系统,明细步骤简单操作
留言信息是之前用php做过的一个例子,现在把它用smarty模板来做 大概是这样子 点击发布信息 然后填写内容,发送后会返回表格,写的内容都会出现在表格里 数据库的数据是这样的: 先建两个文件.php ...
- View的draw机制
View:1.draw//绘制一个View以及他的子View.最好不要覆写该方法,应该覆写onDraw方法来绘制自己.public void draw(Canvas canvas); public v ...
- springcloud 入门 6 (断路器hystrix)
hystrix:断路器 断路器是为了解决服务故障的“雪崩”, 雪崩是指,由于网络原因或者自身的原因,服务并不能保证100%可用,如果单个服务出现问题,调用这个服务就会出现线程阻塞,此时若有大量的请 ...
- 开发之道——读《移山之道——VSTS开发之道》后感
开发之道——读<移山之道——VSTS开发之道>后感 <移山之道——VSTS开发之道>(下简称<移山之道>)是邹欣老师的另一本书.相传很有名的<构建之法> ...
- LeetCode题解之Palindromic Substrings
1.问题描述 2.问题分析 对于每一个字符,以该字符为中心计算回文个数. 3.代码 int countSubstrings(string s) { ; ) ; ; i < s.size(); i ...
- LeetCode题解之Valid Triangle Number
1.题目描述 2.问题分析 暴力计算 3.代码 int triangleNumber(vector<int>& nums) { ; ) return res; ; i < n ...
- 使用python快速搭建本地网站
如果你急需一个简单的Web Server,但你又不想去下载并安装那些复杂的HTTP服务程序,比如:Apache,ISS,Nodejs等.那么, Python 可能帮助你.使用Python可以完成一个简 ...
- SEO-搜索引擎优化
一.定义 SEO(Search Engine Optimization):汉译为搜索引擎优化.是一种方式:利用搜索引擎的规则提高网站在有关搜索引擎内的自然排名.目的是:为网站提供生态式的自我营销解决方 ...
- Java中几种常用数据类型之间转换的方法
Java中几种常用的数据类型之间转换方法: 1. short-->int 转换 exp: short shortvar=0; int intvar=0; shortvar= (short) in ...