• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# BackgroundWorker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



BackgroundWorker类属于命名空间,在下文中一共展示了BackgroundWorker类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: OnTouched

    private void OnTouched()
    {
        if (_backgroundWorker != null) _backgroundWorker.CancelAsync();
        _backgroundWorker = new BackgroundWorker();

        if (string.IsNullOrEmpty(Thread.CurrentThread.Name)) Thread.CurrentThread.Name = "Main";

        Debug.Log("START " + Thread.CurrentThread.Name);
        Plane.InfoStr += "\nS("+Thread.CurrentThread.Name+");";
        _backgroundWorker.DoWork += (o, a) =>
        {
            Debug.Log("INSIDE1 " + Thread.CurrentThread.Name);
            Plane.InfoStr += "IN1("+Thread.CurrentThread.Name+");"+a.Argument+";";
            for (var i = 0; i < 10000000; ++i)
            {
                if (a.IsCanceled) return;

                var n = 67876 + i / 100f;
                var x = Mathf.Pow(n, 3);
            }
            Debug.Log("INSIDE2 " + Thread.CurrentThread.Name);
            Plane.InfoStr += "IN2("+Thread.CurrentThread.Name+");";

            a.Result = a.Argument+"!";
        };
        _backgroundWorker.RunWorkerCompleted += (o, a) =>
        {
            Debug.Log("END " + Thread.CurrentThread.Name);
            Plane.InfoStr += "E("+Thread.CurrentThread.Name+");"+a.Result+";";
        };

        _backgroundWorker.RunWorkerAsync("A1");
    }
开发者ID:karthiksaligrama,项目名称:background-worker-unity3d,代码行数:33,代码来源:Plane.cs


示例3: TestCallDoWorkOnBackgroundThreadAndThenCallOnSuccessOnMainThread

 public void TestCallDoWorkOnBackgroundThreadAndThenCallOnSuccessOnMainThread()
 {
     var strategy = new MockBackgroundWorkerStrategy();
     var operation = new BackgroundWorker<object>(strategy);
     operation.Execute();
     strategy.CheckThatOnDoWorkWasCalled();
 }
开发者ID:d20021,项目名称:LiveSDK-for-Windows,代码行数:7,代码来源:BackgroundWorkerTest.cs


示例4: Initialize

 /// <summary>
 /// Initialize the manager, should be called in OnNavigatedTo of main page.
 /// </summary>
 public void Initialize()
 {
     socket = new StreamSocket();
     dataReadWorker = new BackgroundWorker();
     dataReadWorker.WorkerSupportsCancellation = true;
     dataReadWorker.DoWork += new DoWorkEventHandler(ReceiveMessages);
 }
开发者ID:peatear,项目名称:equilibrium,代码行数:10,代码来源:btConManager.cs


示例5: 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


示例6: 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


示例7: HidDevice

        internal HidDevice(string devicePath)
        {
            this.devicePath = devicePath;

            try
            {
                var hidHandle = OpenDeviceIO(devicePath, NativeMethods.ACCESS_NONE);

                deviceAttributes = GetDeviceAttributes(hidHandle);
                deviceCapabilities = GetDeviceCapabilities(hidHandle);

                CloseDeviceIO(hidHandle);
            }
            catch (Exception exception)
            {
                throw new Exception(string.Format("Error querying HID device '{0}'.", devicePath), exception);
            }

            deviceEventMonitor = new HidDeviceEventMonitor(this);
            deviceEventMonitor.Inserted += DeviceEventMonitorInserted;
            deviceEventMonitor.Removed += DeviceEventMonitorRemoved;

            readWorker = new BackgroundWorker<HidDeviceData>();
            readWorker.Updated += new EventHandler<EventArgs<HidDeviceData>>(readWorker_Updated);
            readWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(readWorker_DoWork);
        }
开发者ID:ClimbTheWorld,项目名称:HidLibrary,代码行数:26,代码来源:HidDevice.cs


示例8: Main

        static void Main(string[] args)
        {
            _tweetQueue = new Queue<string>();
            _worker = new BackgroundWorker();
            _worker.DoWork += new DoWorkEventHandler(DBWrite);

            DateTime executionStart = DateTime.Now;
            while (true)
            {
                Console.Write("-");
                try
                {
                    executionStart = DateTime.Now;
                    ConsumeStream();
                }
                catch (Exception e)
                {
                    Output.Print(_name, "Exception from Run:" + Environment.NewLine + e);
                    while (_worker.IsBusy)
                    {
                        Console.WriteLine("Waiting for worker to finish");
                        Thread.Sleep(1000);
                    }
                    if ((DateTime.Now - executionStart).TotalSeconds < 5)
                    {
                        Output.Print(_name, "Previous failure was quick. Waiting 60 seconds.");
                        Thread.Sleep(59000);
                    }
                }
                Console.WriteLine(".");
                Thread.Sleep(1000);
            }

        }
开发者ID:malimu,项目名称:CrisisTracker,代码行数:34,代码来源:Program.cs


示例9: 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


示例10: BackgroundWorker_CancelAsync_ReportsCancelledWhenWorkerSupportsCancellationIsTrue

        public void BackgroundWorker_CancelAsync_ReportsCancelledWhenWorkerSupportsCancellationIsTrue()
        {
            UnitTestContext context = GetContext();

              int numTimesProgressCalled = 0;

              BackgroundWorker target = new BackgroundWorker();
              target.DoWork += (o, e) =>
              {
            // report progress changed 10 times
            for (int i = 1; i < 11; i++)
            {
              Thread.Sleep(100);
              if (target.CancellationPending)
              {
            e.Cancel = true;
            return;
              }
            }
              };
              target.WorkerSupportsCancellation = true;
              target.RunWorkerCompleted += (o, e) =>
              {
            //  target does not support ReportProgress we shold get a System.InvalidOperationException from DoWork
            context.Assert.IsNull(e.Error);
            context.Assert.IsTrue(e.Cancelled);
            context.Assert.Success();
              };
              target.RunWorkerAsync(null);
              target.CancelAsync();
              context.Complete();
        }
开发者ID:BiYiTuan,项目名称:csla,代码行数:32,代码来源:BackgroundWorkerTests.cs


示例11: 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


示例12: HidDeviceEventMonitor

        public HidDeviceEventMonitor(HidDevice device)
        {
            this.device = device;

            monitor = new BackgroundWorker<bool>();
            monitor.Updated += new EventHandler<EventArgs<bool>>(monitor_Updated);
            monitor.DoWork += new System.ComponentModel.DoWorkEventHandler(monitor_DoWork);
        }
开发者ID:jj-jabb,项目名称:HidLibrary,代码行数:8,代码来源:HidDeviceEventMonitor.cs


示例13: DefaultValues

 public void DefaultValues()
 {
     var backgroundWorker = new BackgroundWorker<object, object, object>();
     Assert.IsTrue(backgroundWorker.ThrowExceptionOnCompleted);
     Assert.IsFalse(backgroundWorker.IsBusy);
     Assert.IsFalse(backgroundWorker.WorkerReportsProgress);
     Assert.IsFalse(backgroundWorker.WorkerSupportsCancellation);
 }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:8,代码来源:BackgroundWorkerTest.cs


示例14: StartBackgroundInitialization

 void StartBackgroundInitialization()
 {
     Log.Info("PictureOfTheDay: Init!");
     pluginBackgroundWorker = new BackgroundWorker();
     pluginBackgroundWorker.WorkerReportsProgress = true;
     pluginBackgroundWorker.WorkerSupportsCancellation = false;
     pluginBackgroundWorker.DoWork += DoWork;
     pluginBackgroundWorker.RunWorkerAsync();
 }
开发者ID:j-b-n,项目名称:MPDomoticz,代码行数:9,代码来源:BackgroundWorker.cs


示例15: 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


示例16: Fallidas

 public Fallidas()
 {
     bckWrk = new BackgroundWorker();
     bckWrk.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bckWrk_DoWork);
     bckWrk.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bckWrk_RunWorkerCompleted);
     aTimer = new System.Timers.Timer(10000);
     aTimer.Elapsed += new ElapsedEventHandler(GrabarFallidas);
     aTimer.Enabled = true;
 }
开发者ID:BenjaOtero,项目名称:trend-pos,代码行数:9,代码来源:fallidas.cs


示例17: StartDownloadEvfInBackGround

 private void StartDownloadEvfInBackGround()
 {
     var backgroundWorker = new BackgroundWorker();
     backgroundWorker.Work(() =>
     {
         while (this.DownloadEvf())
             Thread.Sleep(EosCamera.WaitTimeoutForNextLiveDownload);                
     });
 }
开发者ID:Bill-Lea,项目名称:Canon.Eos.Framework,代码行数:9,代码来源:EosCamera.HandePropertyEvents.cs


示例18: ThrowExceptionOnCompletedFalse

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


示例19: SystemService

        public SystemService()
        {
            _timer = new Timer (10000);
            _timer.Elapsed += Elapsed;
            _timer.Start ();

            _worker = new BackgroundWorker ();
            _worker.DoWork += DoWork;
        }
开发者ID:avdf,项目名称:ddlhelper,代码行数:9,代码来源:SystemService.cs


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# BacnetAddress类代码示例发布时间:2022-05-24
下一篇:
C# BackgroundType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap