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 ...
随机推荐
- 前端开发笔记(3)css基础(中)
上一篇中我们学习了html的标准文档流,下面我们先来看看如何脱离标准流. 脱离标准流 css中一共有三种方法脱离标准流 浮动 绝对定位 固定定位 浮动 我们要搞清楚什么是浮动,先来看一个标准文档流的例 ...
- Oracle 参数文件及相关操作介绍
Oracle 参数文件及相关操作介绍 by:授客 QQ:1033553122 1.服务器参数文件 服务器参数文件是一个二进制文件,作为初始化参数的存储仓库.实例运行时,可用ALTER SYSTEM来改 ...
- 2018-10-16 22:56:13 c language
2018-10-16 22:56:13 c language 我们把上面的步骤总结一下,可以发现一个完整的编程过程是: 编写源文件:这是编程的主要工作,我们要保证代码的语法 100% 正确,不能有任何 ...
- Expo大作战(十九)--expo打包后,发布分用程序到商店的注意事项
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...
- 三种方法实现java调用Restful接口
1,基本介绍 Restful接口的调用,前端一般使用ajax调用,后端可以使用的方法比较多, 本次介绍三种: 1.HttpURLConnection实现 2.HttpClient实现 3.Spring ...
- Java J2EE读取配置文件
package com; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.naming.InitialCon ...
- fatal: cannot create directoryxxxx': Invalid argument
问题:fatal: cannot create directoryxxxx': Invalid argument 环境:git 拉取远程仓库的代码后 原因:同事是mac,这个文件夹命名规则在苹果上没有 ...
- elasticsearch报错之 memory locking requested for elasticsearch process but memory is not locked
安装elasticsearch报错如下: [2019-01-14T03:57:16,453][ERROR][o.e.b.Bootstrap ] [ip-172-31-30-62.ec2.interna ...
- Innodb的体系结构
MySQL的体系结构,两部分组成:MySQL的server层和存储引擎层. 存储引擎层innodb体系结构: innodb的整个体系结构就是由多个内存块组成的缓冲池及多个后台进程组成.我们可以从三方面 ...
- 详解coredump
一,什么是coredump 我们经常听到大家说到程序core掉了,需要定位解决,这里说的大部分是指对应程序由于各种异常或者bug导致在运行过程中异常退出或者中止,并且在满足一定条件下(这里为什么说需要 ...