backgroundworker

Is thread-local storage persisted between backgroundworker invocations?

纵然是瞬间 提交于 2019-12-06 19:54:53
问题 Are backgroundworker threads re-used? Specifically, if I set a named data slot (thread-local storage) during the DoWork() method of a backgroundworker, will the value of that data slot persist, potentially to be found be some other thread at a later time? I wouldn't have thought so, but I have this bug... EDIT: This blog post suggests that BackGroundWorker utilises a ThreadPool, which implies that Threads are re-used. So the question becomes; do re-used threads potentially persist thread

Execute a method in main thread from event handler

拈花ヽ惹草 提交于 2019-12-06 19:52:18
问题 I have a custom Queue class inherited from Queue class. It has an event ItemAdded. In the event handler of this event i am executing a method. But it is running other than main thread, though i want it in main thread. I don't know how to do it. Any suggestion ? //My custom class using System; using System.Collections; //Required to inherit non-generic Queue class. namespace QueueWithEvent { public class SmartQueue:Queue { public delegate void ItemAddedEventHandler(object sender, EventArgs e);

What are the different ways of implementing multithreading in .net

让人想犯罪 __ 提交于 2019-12-06 16:38:03
I have been fighting with multi threading for few days. I dont understand what are different ways of multithreading . I have read little bit about backgroundWorker , little bit about creating an object of thread. Yesterday I saw in delegate example to implement multithreading by calling BeginInvoke . I dont understand are these different ways of multithreading or are same working on same background class. Please help me in making it clear to me. I like this explanations very much. Maybe they help you, too. And then, there is this article by Jon Skeet, too. any thread without a GUI is a

In MVVM, how can I prevent BackgroundWorker from freezing UI?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 15:38:28
问题 First of all, I've seen many similar issues here on SO and around the net. None of these appear to address my particular issue. I have a simple BackgroundWorker whose job is to read a file line-by-line and report progress to indicate how far through it is. There are up to a total of 65,553 lines in the file, so it is important to me that the BackgroundWorker finishes as fast as possible. Since MVVM is built on separation of concerns (SoC) and the decoupling of the View and View-Model, the

Calling SignalR service from a BackgroundWorker in ABP

风格不统一 提交于 2019-12-06 15:35:47
I have a BackgroundWorker which is supposed to broadcast something to all online clients in 5 seconds interval: DeactivationBackgroundWorker: public class DeactivationBackgroundWorker : PeriodicBackgroundWorkerBase, ISingletonDependency { private readonly IRepository<HitchRequest, long> _hitchRequestRepository; private readonly IHitchHub _hitchHub; public DeactivationBackgroundWorker(AbpTimer timer, IRepository<HitchRequest, long> hitchRequestRepository, IHitchHub hitchHub) : base(timer) { _hitchRequestRepository = hitchRequestRepository; Timer.Period = 5000; _hitchHub = hitchHub; } protected

How to implement a UDP listener in the background? (can be used for log4net)

梦想与她 提交于 2019-12-06 15:13:40
问题 I want to run this UDPListener in the background: // launch this in a background thread private static void UDPListen() { IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0) using( var udpClient = new UdpClient(10000)) { while (true) { var buffer = udpClient.Receive(ref remoteEndPoint); var loggingEvent = System.Text.Encoding.Unicode.GetString(buffer); // ... } } } Can I put this inside a Task.Run() and run it in the while() loop? 回答1: This is how I set it up after a bit of reading

Is this thread/background worker design for a C# WPF application OK?

天涯浪子 提交于 2019-12-06 14:28:02
问题 Being new to using threads etc in UI's, can I ask is the following simple design seem OK. Refer to diagram image at link here In particular: a) use of backgroundworker & backgroundworker ProgressChanged to have the aggregator work on a separate thread. So I would need a custom class/type that had all the data I'd need to pass back from the aggregator thread to the UI thread I assume. b) create a separate thread within the aggregator to ensure that the SharpPCap/WinPCap callback method is in a

Background Worker: Make sure that ProgressChanged method has finished before executing RunWorkerCompleted

喜欢而已 提交于 2019-12-06 14:13:44
Let's assume I'm using a Background Worker and I've the following methods: private void bw_DoWork(object sender, DoWorkEventArgs e) { finalData = MyWork(sender as BackgroundWorker, e); } private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e) { int i = e.ProgressPercentage; // Missused for i Debug.Print("BW Progress Changed Begin, i: " + i + ", ThreadId: " + Thread.CurrentThread.ManagedThreadId); // I use this to update a table and an XY-Plot, so that the user can see the progess. UpdateGUI(e.UserState as MyData); Debug.Print("BW Progress Changed End, i: " + i + ", ThreadId:

wpf cancel backgroundworker on application exits

醉酒当歌 提交于 2019-12-06 12:01:23
In my application I have a main windows and into it, in a frame I load a page. This page do a long time task when the user press a button. My problem is that when long task is being doing and the user presses the close button of the main window, the application seems to not finish because I am debugging it in VS2008 and I can see the stop button highlighted. If I want to finish I have to press stop button, the application doesn't stop the debugging automatically on application exit. I thought .NET stops automatically backgroundworkers on application exits but I am not sure after seeing this

Configure Autofac Container for background thread

邮差的信 提交于 2019-12-06 11:47:43
I have an asp.net MVC site which has many components registered using an InstancePerHttpRequest scope, however I also have a "background task" which will run every few hours which will not have an httpcontext. I would like to get an instance of my IRepository which has been registered like this builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)) .InstancePerHttpRequest(); How do I do this from a non http context using Autofac? I think the IRepository should use the InstancePerLifetimeScope There are several ways of how you can do that: The best one in my opinion. You can