Example #1
0
 public string TestMultiThread()
 {
     for (int i = 0; i < 10; i++)
     {
         PrintDelegate pd = new PrintDelegate(print);
         pd.BeginInvoke(i, null, null);
     }
     return("finish");
 }
Example #2
0
 public string TestMultiThread()
 {
     for (int i = 0; i < 10; i++)
     {
         PrintDelegate pd = new PrintDelegate(print);
         pd.BeginInvoke(i, null, null);
     }
     return "finish";
 }
        public static void Test()
        {
            PrintDelegate printDelegate = Print;

            Console.WriteLine("主线程.");
            printDelegate.BeginInvoke("Hello world.", PrintComeplete, printDelegate);
            Console.WriteLine("主线程继续执行...");

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
        }
Example #4
0
        public static void Test()
        {
            PrintDelegate printDelegate = Print;

            Console.WriteLine("主线程");
            IAsyncResult result = printDelegate.BeginInvoke("Hello World.", null, null);

            Console.WriteLine("主线程继续执行...");
            result.AsyncWaitHandle.WaitOne(-1, false);

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
        }
        static void Case2()
        {
            Console.WriteLine("main thread is started.");

            PrintDelegate print = new PrintDelegate(Print);
            IAsyncResult result = print.BeginInvoke("hello world.", null, null);

            Console.WriteLine("main thread is going.");

            result.AsyncWaitHandle.WaitOne(-1, false);//同样阻塞当前线程,等待结果返回

            Console.WriteLine("compeleted.");
        }
        static void Case1()
        {
            Console.WriteLine("main thread is started.");

            PrintDelegate print = new PrintDelegate(Print);
            IAsyncResult result = print.BeginInvoke("hello world.", null, null);

            Console.WriteLine("main thread is going.");

            print.EndInvoke(result);//EndInvode()负责一直阻塞当前线程,等待返回结果后继续执行

            Console.WriteLine("compeleted.");
        }
        public static void Test()
        {
            PrintDelegate printDelegate = Print;

            Console.WriteLine("主线程");

            IAsyncResult result = printDelegate.BeginInvoke("Hello World.", null, null);

            Console.WriteLine("主线程继续执行...");
            //当使用BeginInvoke异步调用方法时,如果方法未执行完,
            //EndInvoke方法就会一直阻塞,直到被调用的方法执行完毕
            printDelegate.EndInvoke(result);

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
        }
        static void Case3()
        {
            Console.WriteLine("main thread is started.");

            PrintDelegate print = new PrintDelegate(Print);
            IAsyncResult result = print.BeginInvoke("hello world.", null, null);

            Console.WriteLine("main thread is going.");

            while (!result.IsCompleted)//轮询执行是否完成
            {
                Console.WriteLine("waiting...");
                Thread.Sleep(200);
            }

            Console.WriteLine("compeleted.");
        }
Example #9
0
        public static void Test()
        {
            PrintDelegate printDelegate = Print;

            Console.WriteLine("主线程:" + Thread.CurrentThread.ManagedThreadId);
            IAsyncResult result = printDelegate.BeginInvoke("Hello world.", null, null);

            Console.WriteLine("主线程:" + Thread.CurrentThread.ManagedThreadId + ",继续执行...");
            while (!result.IsCompleted)
            {
                Console.WriteLine(".");
                Thread.Sleep(500);
            }

            Console.WriteLine("主线程:" + Thread.CurrentThread.ManagedThreadId + "  Press any key to continue...");
            Console.ReadKey(true);
        }
Example #10
0
        static void Main(string[] args)
        {
            // *使用委托实现异步*
            //Console.WriteLine("主线程开始运行,主线程id是:" + Thread.CurrentThread.ManagedThreadId);
            //FooDelegate fooDelegate = Foo;
            //IAsyncResult result = fooDelegate.BeginInvoke("hello world", null, null);
            //Console.WriteLine("当前主线程继续做其他事情······");
            //int n = fooDelegate.EndInvoke(result);
            //Console.WriteLine("回到主线程,程序执行的结果是:" + n);
            //Console.ReadLine();

            //*使用委托回调实现异步*
            Console.WriteLine("主线程开始运行,主线程id是:" + Thread.CurrentThread.ManagedThreadId);
            PrintDelegate printDelegate = Print;

            printDelegate.BeginInvoke("hello world", PrintComplete, printDelegate);
            Console.WriteLine("当前主线程继续做其他事情······");
            Console.ReadLine();
        }
Example #11
0
        public IAsyncResult BeginPrinting(string [] taskarray, List <string> listCode, PrintStatus one, int printer_type)
        {
            AysnPrintDelegate PrintDelegate = null;

            printer = new TtoPrinter();
            printer.initPrintData(taskarray, listCode, one);
            if (printer_type == 0)
            {
                PrintDelegate = new AysnPrintDelegate(printer.DuoMiNuo);
            }
            else if (printer_type == 1)
            {
                PrintDelegate = new AysnPrintDelegate(printer.WDJ);
            }
            else
            {
                PrintDelegate = new AysnPrintDelegate(printer.Markem);
            }
            return(PrintDelegate.BeginInvoke(Printed, PrintDelegate));
        }
Example #12
0
		/// <summary>
		/// Begins the print asynchronously.
		/// </summary>
		/// <param name="clientAETitle">The client AE title.</param>
		/// <param name="remoteAE">The remote AE.</param>
		/// <param name="remoteHost">The remote host.</param>
		/// <param name="remotePort">The remote port.</param>
		/// <param name="filmSession">The film session to print.</param>
		/// <param name="callback">The callback.</param>
		/// <param name="asyncState">State of the async.</param>
		/// <returns></returns>
		public IAsyncResult BeginPrint(string clientAETitle, string remoteAE, string remoteHost, int remotePort, FilmSession filmSession, AsyncCallback callback, object asyncState)
		{
			var printDelegate = new PrintDelegate(this.Print);
			return printDelegate.BeginInvoke(clientAETitle, remoteAE, remoteHost, remotePort, filmSession, callback, asyncState);
		}
Example #13
0
        private void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            PrintDelegate del = new PrintDelegate(PrintReceipt);

            del.BeginInvoke(CleanUpPrinting, del);
        }
Example #14
0
        /// <summary>
        /// Begins the print asynchronously.
        /// </summary>
        /// <param name="clientAETitle">The client AE title.</param>
        /// <param name="remoteAE">The remote AE.</param>
        /// <param name="remoteHost">The remote host.</param>
        /// <param name="remotePort">The remote port.</param>
        /// <param name="filmSession">The film session to print.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="asyncState">State of the async.</param>
        /// <returns></returns>
        public IAsyncResult BeginPrint(string clientAETitle, string remoteAE, string remoteHost, int remotePort, FilmSession filmSession, AsyncCallback callback, object asyncState)
        {
            var printDelegate = new PrintDelegate(this.Print);

            return(printDelegate.BeginInvoke(clientAETitle, remoteAE, remoteHost, remotePort, filmSession, callback, asyncState));
        }
Example #15
0
        /// <summary>
        /// Begins the print asynchronously.
        /// </summary>
        /// <param name="clientAETitle">The client AE title.</param>
        /// <param name="remoteAE">The remote AE.</param>
        /// <param name="remoteHost">The remote host.</param>
        /// <param name="remotePort">The remote port.</param>
        /// <param name="basicFilmSessionModuleIod">The basic film session module iod.</param>
        /// <param name="basicFilmBoxModuleIod">The basic film box module iod.</param>
        /// <param name="imageBoxPixelModuleIods">The image box pixel module iods.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="asyncState">State of the async.</param>
        /// <returns></returns>
        public IAsyncResult BeginPrint(string clientAETitle, string remoteAE, string remoteHost, int remotePort, BasicFilmSessionModuleIod basicFilmSessionModuleIod, BasicFilmBoxModuleIod basicFilmBoxModuleIod, IList<ImageBoxPixelModuleIod> imageBoxPixelModuleIods, AsyncCallback callback, object asyncState)
        {
            PrintDelegate printDelegate = new PrintDelegate(this.Print);

            return printDelegate.BeginInvoke(clientAETitle, remoteAE, remoteHost, remotePort, basicFilmSessionModuleIod, basicFilmBoxModuleIod, imageBoxPixelModuleIods, callback, asyncState);
        }
        public static void ThreadStart()
        {
            PrintDelegate printDelegate = Print;

            Console.WriteLine("主线程");

            //AsyncMethodCaller caller = new AsyncMethodCaller(TestMethodAsync);
            //int threadid = 0;
            ////开启异步操作
            //IAsyncResult result = caller.BeginInvoke(1000, out threadid, callBackMethod, caller);
            //for (int i = 0; i < 10; i++)
            //{
            //    Console.WriteLine("其它业务" + i.ToString());
            //}
            ////调用EndInvoke,等待异步执行完成
            //Console.WriteLine("等待异步方法TestMethodAsync执行完成");
            ////等待异步执行完毕信号
            ////result.AsyncWaitHandle.WaitOne();
            ////Console.WriteLine("收到WaitHandle信号");
            ////通过循环不停的检查异步运行状态
            ////while (result.IsCompleted==false)
            ////{
            ////    Thread.Sleep(100);
            ////    Console.WriteLine("异步方法,running........");
            ////}
            ////异步结束,拿到运行结果
            ////string res = caller.EndInvoke(out threadid, result);
            //////显示关闭句柄
            ////result.AsyncWaitHandle.Close();
            //Console.WriteLine("关闭了WaitHandle句柄");
            //Console.Read();


            //IAsyncResult result = printDelegate.BeginInvoke("Hello World.", null, null);
            //Console.WriteLine("主线程:" + Thread.CurrentThread.ManagedThreadId + ",继续执行...");

            //当使用BeginInvoke异步调用方法时,如果方法未执行完,EndInvoke方法就会一直阻塞,直到被调用的方法执行完毕
            //printDelegate.EndInvoke(result);

            //可以看到,与EndInvoke类似,只是用WaitOne函数代码了EndInvoke而已。
            //result.AsyncWaitHandle.WaitOne(-1, false);

            // 3.轮询
            // 之前提到的两种方法,只能等下异步方法执行完毕,
            // 在完毕之前没有任何提示信息,整个程序就像没有响应一样,用户体验不好,
            // 可以通过检查IasyncResult类型的IsCompleted属性来检查异步调用是否完成,
            // 如果没有完成,则可以适时地显示一些提示信息
            //while (!result.IsCompleted)
            //{
            //    Console.WriteLine("等待中......");
            //    Thread.Sleep(500);
            //}

            printDelegate.BeginInvoke("Hello world.", PrintComplete, printDelegate);
            Console.WriteLine("主线程继续执行...");

            //WrapperSyncMethodAsync("ABC");
            //Trace.WriteLine("Main thread continue...");

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
        }
Example #17
0
        static void Case4()
        {
            Console.WriteLine("main thread is started.");

            PrintDelegate print = new PrintDelegate(Print);
            IAsyncResult result = print.BeginInvoke("hello world.", new AsyncCallback(PrintCompleted), print);//使用回调的方式,不用阻塞当前线程

            Console.WriteLine("main thread is going.");

            Console.WriteLine("compeleted.");
        }
        // Methods
        public IAsyncResult BeginPrint(string clientAETitle, string remoteAE, string remoteHost, int remotePort, BasicFilmSessionModuleIod basicFilmSessionModuleIod, BasicFilmBoxModuleIod basicFilmBoxModuleIod, IList <ImageBoxPixelModuleIod> imageBoxPixelModuleIods, AsyncCallback callback, object asyncState)
        {
            PrintDelegate delegate2 = new PrintDelegate(this.Print);

            return(delegate2.BeginInvoke(clientAETitle, remoteAE, remoteHost, remotePort, basicFilmSessionModuleIod, basicFilmBoxModuleIod, imageBoxPixelModuleIods, callback, asyncState));
        }