I've write a little example:
public class MainClass { public static void Main (string[] args) { var process = new BackGroundProcess (); Console.WriteLine ("--start---"); process.DoWork (new ProcessRequest{ Value = "1254879" }); Console.WriteLine ("--end---"); Console.ReadKey (); } } public class BackGroundProcess { private readonly BackgroundWorker backGroundWorker; public BackGroundProcess () { backGroundWorker = new BackgroundWorker (); backGroundWorker.WorkerSupportsCancellation = false; } public void DoWork(ProcessRequest request){ backGroundWorker.DoWork += DoWork; backGroundWorker.RunWorkerAsync (request); } private void DoWork(object sender, DoWorkEventArgs e) { var param = e.Argument as ProcessRequest; Thread.Sleep (100); Console.WriteLine ("param: " + param.Value); } } public class ProcessRequest { public string Value{ get; set;} }the output is:
--start---
--end---
param: 1254879
No hay comentarios:
Publicar un comentario