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
                    }

                }));

            }

        }

  

原文地址:https://www.cnblogs.com/wgscd/p/9166821.html

时间: 2024-10-18 22:08:05

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

Cannot Login to SQL Server using administrator account

After installing SQL server on a machine, it happens that you connect or disconnect that machine to domain. WHen you do this, the administrator account can no longer access the database engine. The below steps allow you to regain access to the SQL se

mongodb中update方法的upsert和multi

mongodb中的update的形式是这样的: db.collectionName.update(query, obj, upsert, multi); 对于upsert(默认为false):如果upsert=true,如果query找到了符合条件的行,则修改这些行,如果没有找到,则追加一行符合query和obj的行.如果upsert为false,找不到时,不追加. 对于multi(默认为false): 如果multi=true,则修改所有符合条件的行,否则只修改第一条符合条件的行.

Security1:Create Login

Login 用于登陆SQL Server 1,Create Sql Server login CREATE LOGIN TestLoginName with password='J345#$)thb' ,DEFAULT_DATABASE = db_study PASSWORD ='password' Applies to SQL Server logins only. Specifies the password for the login that is being created. You

多线程为什么跑的比单线程还要慢的情况分析及验证

2014-05-04 07:56:50cnblogs.com-Ethan Cai-点击数: 306 "多个人干活比一个人干活要快,多线程并行执行也比单线程要快"这是我学习编程长期以来的想法.然而在实际的开发过程中,并不是所有情况下都是这样.先看看下面的程序(点击下载): ThreadTester是所有Tester的基类.所有的Tester都干的是同样一件事情,把counter增加到100000000,每次只能加1. 1:publicabstractclass ThreadTester

聊一下Python的线程 &amp; GIL

再来聊一下Python的线程 参考这篇文章 https://www.zhihu.com/question/23474039/answer/24695447 简单地说就是作为可能是仅有的支持多线程的解释型语言(perl的多线程是残疾,PHP没有多线程),Python的多线程是有compromise的,在任意时间只有一个Python解释器在解释Python bytecode.Ruby也是有thread支持的,而且至少Ruby MRI是有GIL的. 首先要了解 GIL,全称 Global Interp

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

 Visual Studio是美国微软公司开发的一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具.代码管控工具.集成开发环境(IDE)等等,且所写的目标代码适用于微软支持的所有平台.可以说.NET开发人员离不开它,它可以极大的提高编写软件的效率. Visual Studio作为一个世界级开发工具,当然支持通过插件方式对其功能进行扩展,开发人员可以定制自己的插件来进一步提升Visual Studio的功能. 1 什么是Add In? 所谓的add-in就是一些被

线程与进程-- 简单的解释

最近这段时间小编有点自卑,但是还是要按时的冒一下泡!!!!!! 在学习过程中经常听到进程与线程的概念,这几天了解了下线程与进程之间的关系,把自己的想法分享一下: 感谢:http://www.tuicool.com/articles/vMfIjy 进程(process)和线程(thread)是操作系统的基本概念. 最近,我读到一篇材料,发现有一个很好的类比,可以把它们解释地清晰易懂. 假设我们每个人都有一个房子( 想想眼里就都是泪 ),这个房子有一个很洋气的名字,叫做”Process“,房子里面有

Golang 微框架 Gin 简介

框架一直是敏捷开发中的利器,能让开发者很快的上手并做出应用,甚至有的时候,脱离了框架,一些开发者都不会写程序了.成长总不会一蹴而就,从写出程序获取成就感,再到精通框架,快速构造应用,当这些方面都得心应手的时候,可以尝试改造一些框架,或是自己创造一个. 曾经我以为Python世界里的框架已经够多了,后来发现相比golang简直小巫见大巫.golang提供的net/http库已经很好了,对于http的协议的实现非常好,基于此再造框架,也不会是难事,因此生态中出现了很多框架.既然构造框架的门槛变低了,

Jmeter_初步认识随笔

1. 简介 Apache JMeter是100%纯java桌面应用程序,被设计用来测试客户端/服务器结构的软件(例如web应用程序).它可以用来测试包括基于静态和动态资源程序的性能,例如静态文件,Java Servlets,Java 对象,数据库,FTP 服务器等等.JMeter可以用来在一个服务器.网络或者对象上模拟重负载来测试它的强度或者分析在不同的负载类型下的全面性能. 另外,JMeter能够通过让你们用断言创建测试脚本来验证我们的应用程序是否返回了我们期望的结果,从而帮助我们回归测试我们