Ejemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.dataGVClients.Rows.Add();
            this.dataGVServers.Rows.Add();
            this.dataGVServers.Rows.Add();
            for (int i = 0; i < 1; i++)
            {
                Monitor.StartAddNewServer();
                BackgroundWorker t = new BackgroundWorker();
                t.WorkerReportsProgress = true;
                t.WorkerSupportsCancellation = false;
                t.DoWork += new DoWorkEventHandler(backgroundWorker_DoServerWork);
                t.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ServerProgressChanged);
                // ClientInfo info = new ClientInfo();
                //info.n = threadN++;
                t.RunWorkerAsync();
                Monitor.EndAddNewObject();
            }

            for (int i = 0; i < 5; i++)
            {
                threadN = i;
                Monitor.StartAddNewClient();
                BackgroundWorker t = new BackgroundWorker();
                t.WorkerReportsProgress = true;
                t.WorkerSupportsCancellation = false;
                t.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
                t.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
                Info info = new Info();
                info.n = i;
                Monitor.events.Add(info.n,new System.Threading.ManualResetEvent(true));
                ClientInfo clientInfo = new ClientInfo();
                clientInfo.status = "работа";
                clientInfo.requestCount = 0;
                Monitor.statuses.Add(clientInfo);
                Monitor.results.Add(0);
                t.RunWorkerAsync(info);

            }
        }
Ejemplo n.º 2
0
        public static void Report(int n, int flg)
        {
            lock (lck) {
            if (events.ContainsKey(n) == true) {
            } else {
              events.Add(n, new ManualResetEvent(true));
              ClientInfo stt = new ClientInfo();
              stt.status = "работа";
              stt.time = DateTime.Now;
              stt.requestCount = statuses[n].requestCount;
              statuses[n] = stt;

            }
              }
        }
Ejemplo n.º 3
0
        public static void SendResult(int n, int result)
        {
            results[n] = result;
              lock (lck) {
            queue.Remove(queue.First());
            events[n].Set();
            ClientInfo stt = new ClientInfo();
            stt.status = "работа";
            stt.time = DateTime.Now;
            stt.requestCount = statuses[n].requestCount;
            stt.lastAnsw = result;
            statuses[n] = stt;

              }
        }
Ejemplo n.º 4
0
        public static bool StartAddNewClient()
        {
            lock (lck) {
            if (isCreationMode == true)
              return false;

            if (clients < 5) {
              ClientInfo info = new ClientInfo();
              info.requestCount = 0;
              info.status = "работа";
              info.lastAnsw = info.lastTask = 0;
              statuses.Add(info);
              clients++;
              isCreationMode = true;
              return true;
            } else
              return false;
              }
        }
Ejemplo n.º 5
0
        public static void SendRequest(int n, int task)
        {
            lock (lck) {
            events[n].Reset();
            Request rqst = new Request();
            rqst.n = n;
            rqst.task = task;
            queue.Add(rqst);
            ClientInfo stt = new ClientInfo();
            stt.status = "ожидание ответа";
            stt.time = DateTime.Now;
            stt.requestCount = statuses[n].requestCount + 1;
            stt.lastTask = task;

            statuses[n] = stt;
              }
        }