public MainWindow() { Random portGen = new Random(); //portnum = portGen.Next(49152, 65535); portnum = 1200; InitializeComponent(); IPHostEntry host; String hostName = Dns.GetHostName(); host = Dns.GetHostEntry(hostName); TextBox box = textBox; box.Text = ""; foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { box.Text += String.Format("server {0} port {1}\n", ip.ToString(), portnum); } } myDelegate blah = new myDelegate(message); blah.BeginInvoke(null, null); }
static void Main(string[] args) { Person p1 = new Person("杨先生", "下中国象棋"); //3.实例化一个委托 myDelegate m1 = new myDelegate(Fangfa); m1.BeginInvoke("hans", new AsyncCallback(MyCallBack), p1); Console.ReadLine(); }
private void Run() { try { myDelegate updateDelegate = new myDelegate(StartUpdate); IAsyncResult iResult = updateDelegate.BeginInvoke(new AsyncCallback(CallBack), null); } catch (Exception ex) { MessageBox.Show("升级失败:" + ex.Message.ToString()); this.Close(); } }
public static void Main() { var primero = new myDelegate(Primero); var segundo = new myDelegate(Segundo); IAsyncResult counterResult = primero.BeginInvoke(null, null); IAsyncResult parserResult = segundo.BeginInvoke(null, null); for (int i = 0; i < 50; i++) { Console.WriteLine("main " + i); } }
private void Run() { try { myDelegate updateDelegate = new myDelegate(StartUpdate); IAsyncResult iResult = updateDelegate.BeginInvoke(new AsyncCallback(CallBack), null); } catch (Exception ex) { //启动主程序 System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + Common.GetValByKey("StartApp", false, "FTP")); this.Close(); } }
public IAsyncResult BeginMakeStable(LogRecord record, AsyncCallback callback, object asyncState) { myDelegate del = new myDelegate(_makeStable); return del.BeginInvoke(record, callback, asyncState); }
private void button1_Click(object sender, RoutedEventArgs e) { myDelegate md = SUM; // 둘은 signature가 같기때문에 연결할 수 있음 md.BeginInvoke(((Window2)Application.Current.Windows[2]).label2, SumCallback, "test"); // test는 쓰레기값...? 용도 잘모름 }
private void button_Click(object sender, RoutedEventArgs e) // 이벤트 발생할때 어떤 값을 주면 args안에 담겨서 옴 // sender: window form { myDelegate md = SUM; // 둘은 signature가 같기때문에 연결할 수 있음 md.BeginInvoke(((Window1)Application.Current.Windows[1]).label1, SumCallback, "test"); // test는 쓰레기값...? 용도 잘모름 }
public IAsyncResult BeginMakeStable(LogRecord record, AsyncCallback callback, object asyncState) { myDelegate del = new myDelegate(_makeStable); return(del.BeginInvoke(record, callback, asyncState)); }
private void button_Click(object sender, RoutedEventArgs e) // 이벤트 발생할때 어떤 값을 주면 args안에 담겨서 옴 // sender: window form { myDelegate md = SUM; // 둘은 signature가 같기때문에 연결할 수 있음 md.BeginInvoke(lbl_hello, SumCallback, "test"); // test는 쓰레기값...? 용도 잘모름 }
public int runAddManyNumberDelegate1() { myDelegate md = new myDelegate(addManyNumber); //or, myDelegate md = addManyNumber; //this will return right away IAsyncResult iftAR = md.BeginInvoke("run beginInvoke", null,null ); //busy loop to appreciate the multithreading feeling while (!iftAR.IsCompleted) { Console.WriteLine("MyAsyncDelegate is not completed"); } Console.WriteLine("\n\nMyAsyncDelegate is now compleged"); //calling thread is now blocked until EndInvoke is completed int answer = md.EndInvoke(iftAR); return answer; }