当前位置: 首页>>代码示例>>C#>>正文


C# BackgroundWorker.RunWorkerAsync方法代码示例

本文整理汇总了C#中BackgroundWorker.RunWorkerAsync方法的典型用法代码示例。如果您正苦于以下问题:C# BackgroundWorker.RunWorkerAsync方法的具体用法?C# BackgroundWorker.RunWorkerAsync怎么用?C# BackgroundWorker.RunWorkerAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BackgroundWorker的用法示例。


在下文中一共展示了BackgroundWorker.RunWorkerAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: bgworkercounter

 public void bgworkercounter()
 {
     var backgroundWorker1 = new BackgroundWorker();
     backgroundWorker1.DoWork += backgroundWorker1_DoWork;
     backgroundWorker1.RunWorkerCompleted += backgroundWorker1_RunWorkerCompleted;
     backgroundWorker1.RunWorkerAsync();
 }
开发者ID:Nazgard,项目名称:t2_1stan,代码行数:7,代码来源:ArchiveControl.cs

示例2: Main

    // private static SimpleCompileForm _simpleCompileForm;

    private static void Main(string[] args)
    {
        var worker = new BackgroundWorker();
        worker.DoWork += (sender, e) =>
        {
            try
            {
                _nativeWorkbenchForm = new NativeWorkbenchForm();
                _timer = new System.Windows.Forms.Timer();
                _timer.Stop();
                _timer.Interval = 100;
                _timer.Tick += _timer_Tick;
                _timer.Start();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            Application.EnableVisualStyles();
            Application.Run(_nativeWorkbenchForm);
        };
        worker.RunWorkerAsync();


        Thread.Sleep(-1);
    }
开发者ID:isti37,项目名称:NativeWorkbench,代码行数:28,代码来源:DebugFormLauncher.cs

示例3: Start

 // Use this for initialization
 void Start()
 {
     // init a background worker thread
     BackgroundWorker worker = new BackgroundWorker();
     worker.DoWork += HandleWorkerDoWork;
     worker.RunWorkerAsync();
 }
开发者ID:derFunk,项目名称:unity3d-webplayer-jslogger,代码行数:8,代码来源:JsLoggerThreadExample.cs

示例4: NativeWorkbench

    public NativeWorkbench()
    {
        try
        {
          //  KeyDown += OnKeyDown;
            Tick += OnTick;
        }
        catch (Exception e)
        {
            SaveLoad.Log(e.ToString());
           // Debug.WriteLine(e);
        }


        BackgroundWorker myWorker = new BackgroundWorker();
        myWorker.DoWork += (sender, e) =>
        {
            try
            {
                Application.EnableVisualStyles();
                Application.Run(_nativeWorkbenchForm);
            }
            catch (Exception ex)
            {
                SaveLoad.Log(ex.ToString());
            }
        };
        myWorker.RunWorkerAsync();
    }
开发者ID:isti37,项目名称:NativeWorkbench,代码行数:29,代码来源:NativeWorkbenchScript.cs

示例5: TestCancelAsync

        public void TestCancelAsync()
        {
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += DoWorkExpectCancel;
            bw.WorkerSupportsCancellation = true;

            manualResetEvent3 = new ManualResetEventSlim(false);

            bw.RunWorkerAsync("Message");
            bw.CancelAsync();

            bool ret = manualResetEvent3.Wait(TimeoutLong);
            Assert.True(ret);
            // there could be race condition between worker thread cancellation and completion which will set the CancellationPending to false 
            // if it is completed already, we don't check cancellation
            if (bw.IsBusy) // not complete
            {
                if (!bw.CancellationPending)
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        Wait(TimeoutShort);
                        if (bw.CancellationPending)
                        {
                            break;
                        }
                    }
                }
                // Check again
                if (bw.IsBusy)
                    Assert.True(bw.CancellationPending, "Cancellation in Main thread");
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:34,代码来源:BackgroundWorkerTests.cs

示例6: ThrowExceptionOnCompletedFalse

 public void ThrowExceptionOnCompletedFalse()
 {
     var b = new BackgroundWorker<object, object, object>
                 {
                     ThrowExceptionOnCompleted = false,
                     DoWork = ThrowException
                 };
     b.RunWorkerAsync();
 }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:9,代码来源:BackgroundWorkerTest.cs

示例7: Worker

 public Worker(string[] arguments)
 {
     this.worker = new BackgroundWorker();
     worker.WorkerSupportsCancellation = true;
     worker.WorkerReportsProgress = true;
     worker.DoWork += new DoWorkEventHandler(worker_DoWork);
     worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
     worker.RunWorkerAsync(arguments);
 }
开发者ID:eatonmi,项目名称:Crawler,代码行数:9,代码来源:Program.cs

示例8: FFRKMySqlInstance

 public FFRKMySqlInstance()
 {
     mDatabaseThread = new BackgroundWorker();
     mDatabaseThread.DoWork += mDatabaseThread_DoWork;
     mDatabaseThread.RunWorkerAsync();
     mDatabaseQueue = new BlockingCollection<IDbRequest>();
     mCancellationTokenSource = new CancellationTokenSource();
     mConnectionState = ConnectionState.Disconnected;
 }
开发者ID:JulianoW,项目名称:ffrkx,代码行数:9,代码来源:FFRKMySQLInstance.cs

示例9: FileState

 public FileState()
     : base()
 {
     asyncWriter = new BackgroundWorker();
     asyncWriter.DoWork += new DoWorkEventHandler(WriteDataAsync);
     asyncWriter.RunWorkerCompleted +=
             new RunWorkerCompletedEventHandler(
                 (object sender, RunWorkerCompletedEventArgs e) => { if (postponedWrite) { postponedWrite = false; asyncWriter.RunWorkerAsync(); } }
             );
 }
开发者ID:Elringus,项目名称:BreachedUnity,代码行数:10,代码来源:FileState.cs

示例10: TestBackgroundWorkerBasic

        public void TestBackgroundWorkerBasic()
        {
            var orignal = SynchronizationContext.Current;
            try
            {
                SynchronizationContext.SetSynchronizationContext(null);

                const int expectedResult = 42;
                const int expectedReportCallsCount = 5;
                int actualReportCallsCount = 0;
                var worker = new BackgroundWorker() { WorkerReportsProgress = true };
                var progressBarrier = new Barrier(2, barrier => ++actualReportCallsCount);
                var workerCompletedEvent = new ManualResetEventSlim(false);

                worker.DoWork += (sender, e) =>
                {
                    for (int i = 0; i < expectedReportCallsCount; i++)
                    {
                        worker.ReportProgress(i);
                        progressBarrier.SignalAndWait();
                    }

                    e.Result = expectedResult;
                };
                worker.RunWorkerCompleted += (sender, e) =>
                {
                    try
                    {
                        Assert.Equal(expectedResult, (int)e.Result);
                        Assert.False(worker.IsBusy);
                    }
                    finally
                    {
                        workerCompletedEvent.Set();
                    }
                };
                worker.ProgressChanged += (sender, e) =>
                {
                    progressBarrier.SignalAndWait();
                };

                worker.RunWorkerAsync();

                // wait for singal from WhenRunWorkerCompleted
                Assert.True(workerCompletedEvent.Wait(TimeoutLong));
                Assert.False(worker.IsBusy);
                Assert.Equal(expectedReportCallsCount, actualReportCallsCount);
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(orignal);
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:53,代码来源:BackgroundWorkerTests.cs

示例11: Run

            public void Run()
            {
                worker = new BackgroundWorker();

                worker.DoWork += new DoWorkEventHandler(DoWork);
                worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted);
                worker.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged);
                worker.WorkerReportsProgress = true;
                worker.WorkerSupportsCancellation = true;

                worker.RunWorkerAsync(Options);
            }
开发者ID:JauchOnGitHub,项目名称:csharptoolbox,代码行数:12,代码来源:BackgroundApp.cs

示例12: SendTransform

 void SendTransform()
 {
     var pos = transform.position;
     var angles = transform.localEulerAngles;
     var worker = new BackgroundWorker();
     var time = Time.time;
     worker.DoWork += (sender, e) => {
         ISFSObject obj = NetworkHelper.TransformToSFSObject(pos, angles);
         obj.PutBool("isBlue", IsBlueTeam);
         obj.PutFloat("time", time);
         smartFox.Send(new ObjectMessageRequest(obj));
     };
     worker.RunWorkerAsync();
 }
开发者ID:Daminvar,项目名称:Scatterblocks,代码行数:14,代码来源:NetworkTransformSender.cs

示例13: RunInBackgroundOrNot

 void RunInBackgroundOrNot(Action action)
 {
     if (runInSeparateThread) {
         var worker = new BackgroundWorker ();
         worker.DoWork += delegate(object sender, DoWorkEventArgs e) {
             action ();
         };
         worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) {
             Debug.Log ("Background thread done");
         };
         worker.RunWorkerAsync ();
     } else {
         action ();
         Debug.Log ("Done");
     }
 }
开发者ID:sawakun,项目名称:Sphere_screen,代码行数:16,代码来源:ScriptingDemoUI.cs

示例14: wireless_devices

 public wireless_devices(AdminWindow w)
 {
     mainform = w;
     AddDevice = new RelayCommand(o => SecuredDevices.Add(o as WirelessDevice), o => (o != null && (SecuredDevices.Count <= 1)));
     RemoveDevice = new RelayCommand(o => SecuredDevices.Remove(o as WirelessDevice), o => o != null);
     InitializeComponent();
     WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
     //initialiseLoggingFramework();
     log = Logger.Instance;
     bg = new BackgroundWorker();
     bg.DoWork += new DoWorkEventHandler(bg_DoWork);
     bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bg_RunWorkerCompleted);
     if (!bg.IsBusy)
     {
         bg.RunWorkerAsync();
     }
 }
开发者ID:sumeetjauhar,项目名称:YQ,代码行数:17,代码来源:wireless_devices.xaml.cs

示例15: POSPageViewModel

        public POSPageViewModel()
        {
            this.SaleCommand = new Telerik.Windows.Controls.DelegateCommand(o => this.methodSaleCommand());

            MyImageButtonCatagories = new ObservableCollection<MyImageButtonCatagory>();

            BackgroundWorker imageButtonsCataogryWorker = new BackgroundWorker();
            imageButtonsCataogryWorker.DoWork += new DoWorkEventHandler(imageButtonsCatagoryWorker_DoWork);
            imageButtonsCataogryWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(imageButtonsCatagoryWorker_runworkercompleted);
            imageButtonsCataogryWorker.RunWorkerAsync();

            this._eventAggregator.GetEvent<AmountEnteredEvent>()
               .Subscribe((eventDetail) =>
               {
                   logger.Trace("event received {0}", eventDetail.Id);
                   userEnterAmount(double.Parse(eventDetail.Detail));
               });
        }
开发者ID:function1983,项目名称:GreenP,代码行数:18,代码来源:POSPageViewModel.cs


注:本文中的BackgroundWorker.RunWorkerAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。