Exemple #1
0
        static void Main(string[] arg)
        {
            const int   N         = 15;
            ShowMessage asyncCall = new ShowMessage(AsynchronousMethod);

            // asyncCall を非同期で呼び出す。
            IAsyncResult ar = asyncCall.BeginInvoke(N, null, null);

            // ↓この部分は asyncCall によって呼び出されるメソッドと同時に実行されます。
            for (int i = 0; i < N; ++i)
            {
                Thread.Sleep(2000);
                Console.Write("Main ({0})\n", i);
            }

            // asyncCall の処理が終わるのを待つ。
            asyncCall.EndInvoke(ar);

            Console.Write(" 処理完了\n");
        }
Exemple #2
0
        private void dealProgressValue(int value)
        {
            MethodInvoker action = delegate { dealProgress.Value = value; };

            ShowMessage.BeginInvoke(action);
        }
Exemple #3
0
        private async void httpAccess()
        {
            dealProgressValue(0);
            showMessageInfo("Start Http Request... \n");
            try
            {
                var handler = new HttpClientHandler()
                {
                    AutomaticDecompression = DecompressionMethods.None
                };

                using (var client = new HttpClient(handler))
                {
                    dealProgressValue(10);
                    showMessageInfo("Send Data To Http Server... \n");
                    var httpResponseMessage = await client.GetAsync("http://" + IPAddress.Text + ":" + IPPort.Text + "/common/eeprom.php?version=3&mac=" + currentMAC.Text.Replace(":", ""));

                    if (httpResponseMessage.StatusCode == HttpStatusCode.OK)
                    {
                        var ret_json = await httpResponseMessage.Content.ReadAsStringAsync();

                        showMessageInfo("Recv Json Data From Http Server... \n");
                        showMessageInfo(ret_json + "\n");
                        dealProgressValue(50);

                        MethodInvoker action = delegate {
                            dynamic json = JValue.Parse(ret_json)  as dynamic;
                            if (json["status"].ToString() == "ok")
                            {
                                Console.WriteLine(currentMAC.Text);
                                if (MACSQLite.queryCount("macs") > 0)
                                {
                                    // 删除MAC,并刷新listview
                                    MACSQLite.deleteMac("macs", currentMAC.Text);
                                    refreshListView();
                                }
                                else
                                {
                                    currentMAC.Text = "00:00:00:00:00:00";
                                }
                                showMessageInfo("Has Delete MAC Database.\r\n");
                                HttpWrite.BackColor = Color.Green;
                                dealProgressValue(90);
                            }
                            else
                            {
                                showMessageInfo("Delete MAC Error.\r\n");
                                HttpWrite.BackColor = Color.Red;
                                dealProgressValue(0);
                            }

                            dealProgressValue(100);
                            HttpWrite.Enabled = true;
                        };
                        ShowMessage.BeginInvoke(action);
                    }
                }
            }
            catch (Exception ex)
            {
                showMessageInfo(ex.ToString());
                MethodInvoker action = delegate {
                    HttpWrite.BackColor = Color.Red;
                    HttpWrite.Enabled   = true;
                };
                ShowMessage.BeginInvoke(action);
                dealProgressValue(0);
            }
        }
Exemple #4
0
        private void showMessageInfo(String mesg)
        {
            MethodInvoker action = delegate { ShowMessage.AppendText(mesg); };

            ShowMessage.BeginInvoke(action);
        }