private void button3_Click(object sender, EventArgs e) { if (IsCountDone == true) { IsCountDone = false; Thread 白平衡執行序 = new Thread(new ThreadStart(delegate { MethodCaller mc = new MethodCaller(AutoWhiteBalance); if (pictureBox3.Image != null) { Bitmap bm = new Bitmap(pictureBox3.Image); IAsyncResult result = mc.BeginInvoke(bm, null, null); Bitmap bm1 = mc.EndInvoke(result);//用於接收返回值 pictureBox3.Image = bm1; } else if (pictureBox1.Image != null) { Bitmap bm = new Bitmap(pictureBox1.Image); IAsyncResult result = mc.BeginInvoke(bm, null, null); Bitmap bm1 = mc.EndInvoke(result);//用於接收返回值 pictureBox3.Image = bm1; //AutoWhiteBalance(bm); //pictureBox3.Image = bm; } else { MessageBox.Show("尚未選擇來源圖檔"); } })); 白平衡執行序.Start(); } else { MessageBox.Show("圖片運算尚未完成,請稍後"); } //Bitmap bm = new Bitmap(pictureBox1.Image); //IAsyncResult result = mc.BeginInvoke(bm, null, null); //Bitmap bm1 = mc.EndInvoke(result);//用於接收返回值 //pictureBox3.Image = bm1; //if(pictureBox3.Image != null) //{ // pictureBox3.Image.Dispose(); //} //if(pictureBox1.Image != null) //{ // Bitmap bitmap; // bitmap = new Bitmap(pictureBox1.Image); // //ContrastP(bitmap, 圖像對比數值); // pictureBox3.Image = bitmap; //} //else //{ // MessageBox.Show("尚未選擇來源圖檔"); //} }
private void btnLogin_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtNkPsw.Text) || string.IsNullOrEmpty(txtRtIp.Text) || string.IsNullOrEmpty(txtRtPsw.Text)) { MessageBox.Show("请在设置中填写完整的信息!"); } else if (dialer.IsNetConnected()) { ChangeStatus(true, "网络已连接,无需拨号。", 4); } else { string acc; btnLogin.Text = "正在截取..."; Console.WriteLine("正在截取创翼宽带帐号"); ChangeStatus(false, "1/4 " + "正在截取创翼宽带帐号", 1); MethodCaller mc = new MethodCaller(EventListenTask); IAsyncResult result = mc.BeginInvoke(null, null); acc = mc.EndInvoke(result); ChangeStatus(false, "1/4 " + @"成功截取帐号\r" + acc, 1); Console.WriteLine(@"成功截取帐号\r" + acc); acc = "\r" + acc; dialer.BeginRouterDial(txtRtIp.Text, txtRtPsw.Text, acc, txtNkPsw.Text); } }
private void simpleButton导入_Click(object sender, EventArgs e) { simpleButton导入.Enabled = false; ConnDB conn = new ConnDB(); string file = textEditFile.Text.ToString().Trim(); string sheet = comboBoxSheet.Text.ToString(); if (file == "") { MessageBox.Show("没有选择文件", "提示信息", MessageBoxButtons.OK); simpleButton导入.Enabled = true; } else if (sheet == "") { MessageBox.Show("请选择EXCEL表", "提示信息", MessageBoxButtons.OK); simpleButton导入.Enabled = true; } else { Clear(); labeMsg.Text = "正在导入,请等待"; MethodCaller mc = new MethodCaller(Import); IAsyncResult result = mc.BeginInvoke(file, sheet, AsyncShowDetail, mc); } }
private void simpleButton导入_Click(object sender, EventArgs e) { simpleButton导入.Enabled = false; simpleButton清空.Enabled = false; ConnDB conn = new ConnDB(); string file = textEditFile.Text.ToString().Trim(); string sheet = comboBoxSheet.Text.ToString(); //string sql = "select * from COST_HH_STANDARD_HOURS where cmonth = '" + dateTimePickerMonth.Text + "'"; //int rows = conn.ReturnRecordCount(sql); //if (rows > 0) //{ // MessageBox.Show("该月标工已经存在,要重新导入,请先清空该月数据!"); // simpleButton导入.Enabled = true; // simpleButton清空.Enabled = true; //} //else if (file == "") { MessageBox.Show("没有选择文件", "提示信息", MessageBoxButtons.OK); simpleButton导入.Enabled = true; simpleButton清空.Enabled = true; } else if (sheet == "") { MessageBox.Show("请选择EXCEL表", "提示信息", MessageBoxButtons.OK); simpleButton导入.Enabled = true; simpleButton清空.Enabled = true; } else { MethodCaller mc = new MethodCaller(Import); IAsyncResult result = mc.BeginInvoke(file, sheet, AsyncShowDetail, mc); } }
public void ResetUpdate(string name, string path) { if (irDir.TryGetValue(name, out IAsyncResult ir)) { if (ir.IsCompleted) { Action <UserControl1, int, int> updateProgress = progressBarShow; MethodCaller mc = new MethodCaller(FTPHelper.FtpUploadBroken); //启动上传的异步委托 IAsyncResult rets = mc.BeginInvoke(path, pathStr1, updateProgress, null, null); Stopwatch time = new Stopwatch(); time.Start(); tempChange tc = new tempChange(UpdateResult); tc.BeginInvoke(mc, rets, path, time, -1, null, null); } } foreach (UserControl1 item in panel1.Controls) { if (item.label1.Text == name) { item.label2.Text = "上传中"; break; } } keyValues[name] = 2; }
private void simpleButtonImport_Click(object sender, EventArgs e) { //Import(); simpleButtonImport.Enabled = false; simpleButtonClear.Enabled = false; MethodCaller mc = new MethodCaller(Import); IAsyncResult result = mc.BeginInvoke(AsyncShowDetail, mc); }
private void Form1_Load(object sender, EventArgs e) { MethodCaller mc = new MethodCaller(Read); IAsyncResult result = mc.BeginInvoke(@"C:\Users\lflx1\source\repos\ftpSwitch\dbs\psw.txt", null, null); PswList = mc.EndInvoke(result); ShowMsg("密码字典读取完成,最终行为:" + makePsw(PswList[PswList.Count - 1])); }
private void simpleButtonImport_Click(object sender, EventArgs e) { //Thread th = new Thread(Import); //th.IsBackground = true; //th.Start(); simpleButtonImport.Enabled = false; simpleButtonClear.Enabled = false; MethodCaller mc = new MethodCaller(Import); IAsyncResult result = mc.BeginInvoke(AsyncShowDetail, mc); }
private void trackBar2_Scroll(object sender, EventArgs e) { if (IsCountDone == true) { IsCountDone = false; Thread 白平衡執行序 = new Thread(new ThreadStart(delegate { MethodCaller mc = new MethodCaller(AutoWhiteBalance); Bitmap bm = new Bitmap(pictureBox1.Image); IAsyncResult result = mc.BeginInvoke(bm, null, null); Bitmap bm1 = mc.EndInvoke(result);//用於接收返回值 pictureBox3.Image = bm1; })); 白平衡執行序.Start(); IsCountDone = true; } else { MessageBox.Show("圖片運算尚未完成,請稍後"); } //trackBar1.Value = 滑條數值; //int 滑條數值; //滑條數值 = trackBar2.Value-255; ////圖像對比數值 = 滑條數值; //if (pictureBox3.Image != null) //{ // Bitmap bitmap; // bitmap = new Bitmap(pictureBox3.Image); // //LDPic(bitmap, -1); // //LightUpPic(bitmap,1); // AutoWhiteBalance(bitmap); // pictureBox3.Image.Dispose(); // pictureBox3.Image = bitmap; //} //else if (pictureBox1.Image != null) //{ // Bitmap bitmap; // bitmap = new Bitmap(pictureBox1.Image); // //LDPic(bitmap, -1); // //LightUpPic(bitmap,1); // AutoWhiteBalance(bitmap); // pictureBox3.Image = bitmap; //} //else //{ // MessageBox.Show("尚未選擇來源圖檔"); //} }
/// <summary> /// 异步计算 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button_Copy_Click(object sender, RoutedEventArgs e) { Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 5; i++) { MethodCaller mc = TransfeDate; string name = "2017-04-14,2017-06-23";//输入参数 AsyncCallback asyncballback = t => Console.WriteLine("这里是AsyncCallback回调{0},当前线程id{1}", t.AsyncState, Thread.CurrentThread.ManagedThreadId); IAsyncResult result = mc.BeginInvoke(name, asyncballback, "w"); Console.WriteLine("{0},当前线程id{1}", "异步程序正在执行...", Thread.CurrentThread.ManagedThreadId); } sw.Stop(); TimeSpan ProGramts = sw.Elapsed; Console.WriteLine("-{0},当前线程id{1},耗时:{2}", "异步", Thread.CurrentThread.ManagedThreadId, +ProGramts.Seconds + "秒" + ProGramts.Milliseconds + "\r\n"); }
public delegate string MethodCaller(string date);//定义个代理 static void Main6(string[] args) { string workdir = Directory.GetCurrentDirectory();//应用程序当前工作目录 if (1 == 1) { try { System.Console.Write("请输入要测试的方法,1为异步,2为同步:\r\n"); string e = System.Console.ReadLine().ToString(); //日期路径 //var cornurl = @"D:\DuPontWeb\ApiPresentation\FileJson"; //DirectoryInfo theFolder = new DirectoryInfo(cornurl); ////DirectoryInfo[] dirInfo = theFolder.GetDirectories(); ////遍历文件夹 ////foreach (DirectoryInfo NextFolder in dirInfo) ////{ // FileInfo[] fileInfo = theFolder.GetFiles(); // foreach (FileInfo NextFile in fileInfo) //遍历文件 // { // string filename=NextFile.Name; // System.Console.WriteLine(filename.Substring(0,filename.IndexOf('.'))); // } ////} Stopwatch sw = new Stopwatch(); sw.Start(); if (e == "1") { for (int i = 0; i < 5; i++) { //string dt = Convert.ToDateTime("2017年04月13日").ToString("yyyy-MM-dd"); MethodCaller mc = new MethodCaller(TransfeDate); //实例化委托 string name = "2017-04-14,2017-06-23"; //输入参数 //mc += TransfeDate; //AsyncCallback asyncballback = t => System.Console.WriteLine("这里是AsyncCallback回调{0},当前线程id{1}", t.AsyncState, Thread.CurrentThread.ManagedThreadId); //IAsyncResult result = mc.BeginInvoke(name, asyncballback, ansycback("w")); IAsyncResult result = mc.BeginInvoke(name, null, null); //mc.Invoke(name); // mc(name); //if(!result.IsCompleted) //{ System.Console.WriteLine("{0},当前线程id{1}", "程序正在执行...", Thread.CurrentThread.ManagedThreadId); // } //string myname = mc.EndInvoke(result);//用于接收返回值 ,會耗時 } } else if (e == "2") { for (int i = 0; i < 5; i++) { string myname = TransfeDate("2017-04-14,2017-06-23"); System.Console.WriteLine("{0},当前线程id{1}", "程序正在执行...", Thread.CurrentThread.ManagedThreadId); } } else if (e == "6") { int s = AnsycbackForCache("w"); System.Console.WriteLine("{0}", s); } //string myname = TransfeDate("2017-04-14,2017-06-23,2017-06-23"); //string date = TransfeDate("2017年04月13日、2017年04月14日、"); sw.Stop(); TimeSpan ProGramts = sw.Elapsed; System.Console.Write("运行时间:" + ProGramts.Seconds + "秒" + ProGramts.Milliseconds + "\r\n"); System.Console.ReadLine(); } catch (Exception ex) { string logErrstring = DateTime.Now.ToString("\r\n---------MM/dd/yyyy HH:mm:ss,fff---------\r\n") + ex.Message; throw; } } System.Console.ReadLine(); }
public void MSOXCRPC_S02_TC04_TestEcDoAsyncWaitExFail() { this.CheckTransport(); #region Client connects with Server this.pcbAuxOut = ConstValues.ValidpcbAuxOut; this.returnValue = this.oxcrpcAdapter.EcDoConnectEx( ref this.pcxh, TestSuiteBase.UlIcxrLinkForNoSessionLink, ref this.pulTimeStamp, null, this.userDN, ref this.pcbAuxOut, this.rgwClientVersion, out this.rgwBestVersion, out this.picxr); Site.Assert.AreEqual <uint>(0, this.returnValue, "EcDoConnectEx should succeed, and send Session Context Handle (CXH) to EcDoAsyncConnectEx for testing EcDoAsyncWaitEx. '0' is expected to be returned. The returned value is {0}.", this.returnValue); #endregion #region Call EcDoAsyncConnectEx this.returnValue = this.oxcrpcAdapter.EcDoAsyncConnectEx(this.pcxh, ref this.pacxh); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCRPC_R713, the returned value of method EcDoAsyncConnectEx is {0}.", this.returnValue); // Verify MS-OXCRPC requirement: MS-OXCRPC_R713 Site.CaptureRequirementIfAreEqual <uint>( 0, this.returnValue, 713, @"[In EcDoAsyncConnectEx Method (opnum 14)] Return Values: If the method succeeds, the return value is 0."); #endregion #region Call EcDoAsyncWaitEx when pacxh is invalid this.pcxhInvalid = (IntPtr)ConstValues.InvalidPcxh; this.returnValueForInvalidCXH = this.oxcrpcAdapter.EcDoAsyncWaitEx(this.pcxhInvalid, out this.isNotificationPending); Site.Assert.AreNotEqual <uint>(0, this.returnValueForInvalidCXH, "EcDoAsyncWaitEx should not succeed if the CXH is invalid. '0' isn't expected to be returned. The returned value is {0}.", this.returnValueForInvalidCXH); #endregion #region Capture code. // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCRPC_R1228, the return value of EcDoAsyncWaitEx with ACXH valid is {0}, the return value of EcDoAsyncWaitEx with ACXH invalid is {1}.", this.returnValue, this.returnValueForInvalidCXH); // Verify MS-OXCRPC requirement: MS-OXCRPC_R1228 // When the ACXH is returned from EcDoAsyncWaitEx method, the call is successful. While the ACXH is not returned from the EcDoAsyncWaitEx method, the call is failed. // If the code can reach here, this requirement is verified. bool isVerifyR1228 = (this.returnValue == ResultSuccess) && (this.returnValueForInvalidCXH != ResultSuccess); Site.CaptureRequirementIfIsTrue( isVerifyR1228, 1228, @"[In Message Processing Events and Sequencing Rules] Method EcDoAsyncWaitEx: The method requires an active asynchronous context handle returned from the EcDoAsyncConnectEx method on the EMSMDB interface."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCRPC_R1232, the return value of EcDoAsyncWaitEx with ACXH valid is {0}, the return value of EcDoAsyncWaitEx with ACXH invalid is {1}.", this.returnValue, this.returnValueForInvalidCXH); // Verify MS-OXCRPC requirement: MS-OXCRPC_R1232 // Since the context of R1232 is similar with R1228, if the R1228 is verified, it means R1232 is verified. bool isVerifyR1232 = isVerifyR1228; Site.CaptureRequirementIfIsTrue( isVerifyR1232, 1232, @"[In EcDoAsyncWaitEx Method (opnum 0)] This call [EcDoAsyncWaitEx] requires an active asynchronous context handle to be returned from the EcDoAsyncConnectEx method on the EMSMDB interface, as specified in section 3.1.4.1."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCRPC_R310, the return value of EcDoAsyncWaitEx with ACXH valid is {0}, the return value of EcDoAsyncWaitEx with ACXH invalid is {1}.", this.returnValue, this.returnValueForInvalidCXH); // Verify MS-OXCRPC requirement: MS-OXCRPC_R310 // Since the context of R310 is similar with R1228, if the R1228 is verified, it means R310 is verified. bool isVerifyR310 = isVerifyR1228; Site.CaptureRequirementIfIsTrue( isVerifyR310, 310, @"[In Protocol Details] All method calls that require a valid asynchronous context handle [EcDoAsyncWaitEx] are listed in the following table."); if (Common.IsRequirementEnabled(1908, this.Site)) { // Add the debug information this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCRPC_R1908"); // Verify MS-OXCRPC requirement: MS-OXCRPC_R1908 this.Site.CaptureRequirementIfAreNotEqual <uint>( TestSuiteBase.ResultSuccess, this.returnValueForInvalidCXH, 1908, @"[In Appendix B: Product Behavior] Implementation does reject the request if the asynchronous context handle is invalid. (<39> Section 3.3.4.1: Exchange 2007 and Exchange 2010 follow this behavior.)"); } #endregion #region Call EcDoAsyncWaitEx with an EcDoAsyncWaitEx call outstanding on this ACXH uint returnValueOfFirstCall = 0; uint returnValueOfSecondCall = 0; MethodCaller asyncThread = new MethodCaller( () => { return(this.oxcrpcAdapter.EcDoAsyncWaitEx(this.pacxh, out this.isNotificationPending)); }); IAsyncResult result = asyncThread.BeginInvoke(null, null); returnValueOfSecondCall = this.oxcrpcAdapter.EcDoAsyncWaitEx(this.pacxh, out this.isNotificationPending); returnValueOfFirstCall = asyncThread.EndInvoke(result); Site.Log.Add(LogEntryKind.Debug, string.Format("The return value of the first EcDoAsyncWaitEx method is {0}", returnValueOfFirstCall)); Site.Log.Add(LogEntryKind.Debug, string.Format("The return value of the second EcDoAsyncWaitEx method is {0}", returnValueOfSecondCall)); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCRPC_R1343"); bool isR1343Verified = returnValueOfSecondCall == 0x000007EE || returnValueOfFirstCall == 0x000007EE; // Verify MS-OXCRPC requirement: MS-OXCRPC_R1343 Site.CaptureRequirementIfIsTrue( isR1343Verified, 1343, @"[In EcDoAsyncWaitEx Method (opnum 0)] [Return Values] [Rejected (0x000007EE)] An EcDoAsyncWaitEx method call is already outstanding on this asynchronous context handle.<39>"); #endregion #region Client disconnects with Server this.returnValue = this.oxcrpcAdapter.EcDoDisconnect(ref this.pcxh); #endregion }
static void Main(string[] args) { string workdir = Directory.GetCurrentDirectory();//应用程序当前工作目录 if (1 == 1) { try { //引用类型,是一个引用的地址,两个对象,指向同一个地址,修改了,会发生变化。 //student s1 = new student(); //student s2 = new student(); //s1.age = 18;Repository //Utility,global,Repository,Presentation //s2 = s1; //s2.age = 20; int o = 10; int j = o; j = 11; Console.Write(string.Format("o:{0},j:{1}", o, j)); //Console.Write(string.Format("s1:{0},s2:{1}",s1.age,s2.age)); Console.Write("请输入要测试的方法,1为异步,2为同步:\r\n"); string e = Console.ReadLine().ToString(); //日期路径 //var cornurl = @"D:\DuPontWeb\ApiPresentation\FileJson"; //DirectoryInfo theFolder = new DirectoryInfo(cornurl); ////DirectoryInfo[] dirInfo = theFolder.GetDirectories(); ////遍历文件夹 ////foreach (DirectoryInfo NextFolder in dirInfo) ////{ // FileInfo[] fileInfo = theFolder.GetFiles(); // foreach (FileInfo NextFile in fileInfo) //遍历文件 // { // string filename=NextFile.Name; // Console.WriteLine(filename.Substring(0,filename.IndexOf('.'))); // } ////} Stopwatch sw = new Stopwatch(); sw.Start(); if (e == "1") { for (int i = 0; i < 5; i++) { //string dt = Convert.ToDateTime("2017年04月13日").ToString("yyyy-MM-dd"); MethodCaller mc = TransfeDate; string name = "2017-04-14,2017-06-23";//输入参数 //AsyncCallback asyncballback = t => Console.WriteLine("这里是AsyncCallback回调{0},当前线程id{1}", t.AsyncState, Thread.CurrentThread.ManagedThreadId); //IAsyncResult result = mc.BeginInvoke(name, asyncballback, ansycback("w")); IAsyncResult result = mc.BeginInvoke(name, null, null); //if(!result.IsCompleted) //{ Console.WriteLine("{0},当前线程id{1}", "程序正在执行...", Thread.CurrentThread.ManagedThreadId); //} //string myname = mc.EndInvoke(result);//用于接收返回值 ,會耗時 } } else { for (int i = 0; i < 5; i++) { string myname = TransfeDate("2017-04-14,2017-06-23"); Console.WriteLine("{0},当前线程id{1}", "程序正在执行...", Thread.CurrentThread.ManagedThreadId); } } //string myname = TransfeDate("2017-04-14,2017-06-23,2017-06-23"); //string date = TransfeDate("2017年04月13日、2017年04月14日、"); sw.Stop(); TimeSpan ProGramts = sw.Elapsed; Console.Write("运行时间:" + ProGramts.Seconds + "秒" + ProGramts.Milliseconds + "\r\n"); Console.ReadLine(); } catch (Exception ex) { string logErrstring = DateTime.Now.ToString("\r\n---------MM/dd/yyyy HH:mm:ss,fff---------\r\n") + ex.Message; IOHelper.WriteLogToFile(logErrstring, workdir + @"\DuPontServiceyumiLog"); } } Console.ReadLine(); }
public void MSOXCMAPIHTTP_S01_TC07_SimultaneousRequestWithinSameSessionContext() { this.CheckMapiHttpIsSupported(); MailboxResponseBodyBase responseBody; #region Send a valid Connect request type to establish a Session Context with the server. WebHeaderCollection connectHeaders = new WebHeaderCollection(); ConnectSuccessResponseBody connectResponse = this.ConnectToServer(out connectHeaders); #endregion #region Send two Execute request that includes Logon ROP to server simultaneously uint firstResponseCode; uint secondResponseCode; CookieCollection firstCookies = new CookieCollection(); CookieCollection secondCookies = new CookieCollection(); foreach (Cookie cookie in AdapterHelper.SessionContextCookies) { Cookie c = new Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain); firstCookies.Add(c); secondCookies.Add(c); } MethodCaller asyncThread = new MethodCaller( () => { return this.ExecuteLogonROP(firstCookies); }); IAsyncResult result = asyncThread.BeginInvoke(null, null); secondResponseCode = this.ExecuteLogonROP(secondCookies); firstResponseCode = asyncThread.EndInvoke(result); // Add the debug information this.Site.Log.Add( LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1228: When the client has issued simultaneous requests within a Session Context,the first X-Response header is {0} and the second X-Response header is {1}.", firstResponseCode, secondResponseCode); // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1228 bool isVerifiedR1228 = firstResponseCode == 15 || secondResponseCode == 15; this.Site.CaptureRequirementIfIsTrue( isVerifiedR1228, 1228, @"[In Responding to a Connect or Bind Request Type Request] If the server detects that the client has issued simultaneous requests within a Session Context, the server MUST fail every subsequent request with a value of 15 (""Invalid Sequence"" error) in the X-ResponseCode header."); // If the R1228 has been verified, then server return the X-ResponseCode 15 when the request has violated the sequencing requirement of one request at a time per Session Context. // So R151 will be verified. this.Site.CaptureRequirement( 151, @"[In X-ResponseCode Header Field] Invalid Sequence (15): The request has violated the sequencing requirement of one request at a time per Session Context."); #endregion #region Send a Disconnect request type request to destroy the Session Context. this.Adapter.Disconnect(out responseBody); #endregion }