BackgroundWorker RunWorkerCompleted Event

If the BackgroundWorker was created from the UI thread, then the RunWorkerCompleted event will also be raised on the UI thread. If it was created from a background thread, the event will be raised on an undefined background thread (not necessarily the same thread, unless you’re using a custom SynchronizationContext). Interestingly, this doesn’t seem to … Read more

C#: Do I need to dispose a BackgroundWorker created at runtime?

Yes, you should dispose of the background worker. You may find it easier to use ThreadPool.QueueUserWorkItem(…) which doesn’t require any clean up afterwards. Additional detail on why you should always call Dispose(): Although if you look in the BackgroundWorker class it doesn’t actually do any thread clean up in it’s dispose method, it is still … Read more

WPF BackgroundWorker vs. Dispatcher

The main difference between the Dispatcher and other threading methods is that the Dispatcher is not actually multi-threaded. The Dispatcher governs the controls, which need a single thread to function properly; the BeginInvoke method of the Dispatcher queues events for later execution (depending on priority etc.), but still on the same thread. BackgroundWorker on the … Read more

polling with delayed_job

Let’s start with the API. I’d like to have something like the following. @available.working? # => true or false, so we know it’s running @available.finished? # => true or false, so we know it’s finished (already ran) Now let’s write the job. class AwesomeJob < Struct.new(:options) def perform do_something_with(options[:var]) end end So far so good. … Read more

File Copy with Progress Bar

You need something like this: public delegate void ProgressChangeDelegate(double Percentage, ref bool Cancel); public delegate void Completedelegate(); class CustomFileCopier { public CustomFileCopier(string Source, string Dest) { this.SourceFilePath = Source; this.DestFilePath = Dest; OnProgressChanged += delegate { }; OnComplete += delegate { }; } public void Copy() { byte[] buffer = new byte[1024 * 1024]; // … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)