FAQ Database Discussion Community


Can't update Image binding from BackgroundWorker

c#,wpf,mvvm,backgroundworker,mvvm-light
I am getting "An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll Additional information: Must create DependencySource on same Thread as the DependencyObject." XAML: <ListBox x:Name="AutoListBox" ItemsSource="{Binding AutoList}" Visibility="{Binding AutoListVisibility}"> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem"> <EventSetter Event="MouseDoubleClick" Handler="EventSetter_OnHandler"></EventSetter> </Style>...

.NET BackgroundWorker RunWorkerAsync() oddly gets called twice

c#,.net,asynchronous,service,backgroundworker
CODE UPDATED TO REFLECT ANSWER: SAME PROBLEM STILL OCCURS This class is supposed to run all tasks in the list, sleep and then wake up and repeat the process infinitely. For some reason though, after the first sleep, the sleepThread.RunWorkerAsync() call gets called twice for some reason. I can obviously...

Using DispatcherTimer with a BackgroundWorker and a ProgressBar

c#,wpf,multithreading,backgroundworker,dispatchertimer
I've created a simple app that adds 10 times a string to a ListView every second and displays it. All this is done using a BackgroundWorker and a ProgressBar that shows the adding progress. My question is, since I've heard that pausing a thread is very dangerous and can lead...

ASP.NET - start a background task without returning any results and blocking the user

c#,asp.net,asynchronous,backgroundworker
I'm working on a project that when the user's registration is finished, there are some large file that has to be copied to some other locations and sometimes it takes around 10 min to copy everything. I don't need the user to be notified and I don't need to show...

Quitting BackgroundWorker using flag

c#,multithreading,backgroundworker
Imagine I Have such code: private bool flag = false; public SomeClass() { public void setup() { worker = new BackgroundWorker(); worker.DoWork += worker_DoWork; if(!worker.IsBusy) worker.RunWorkerAsync(); } void worker_DoWork(object sender, DoWorkEventArgs e) { if(flag == true) return; //whatever You want the background thread to do... SomeClass.SomeStaticMethodWhichHasLoopInside(); } } When user...

Odd behavior using BackgroundWorker with Thread.Sleep

c#,.net,multithreading,backgroundworker
I have never seen anything before like this. I am using Visual Studio 2015 preview and verified it on Visual Studio 2012. private void InitializeBackgroundWorkers() { MONITOR.WorkerReportsProgress = true; MONITOR.WorkerSupportsCancellation = true; MONITOR.DoWork += new DoWorkEventHandler(MONITOR_DoWork); MONITOR.ProgressChanged += new ProgressChangedEventHandler(MONITOR_ProgressChanged); MONITOR.RunWorkerCompleted += new RunWorkerCompletedEventHandler(MONITOR_WorkCompleted); MONITOR2.WorkerReportsProgress = true;...

How to return data from a BackgroundWorker in c++?

c++-cli,backgroundworker
I've got a BackgroundWorker continually reading data from a USB device. I want to parse that data, then feed it back to my main GUI thread to update a plot and save it to a file. I suspect the way to do this is using ReportProgress, but I'm not sure...

Visual Basic: How I Can put my work at backgroundworker

vb.net,multithreading,backgroundworker
I'm trying to do screenshot every x second and run it on backgroundworker but I can't stop it. Here is my class Form: Imports System.IO Imports System.Drawing.Imaging Imports System.Threading Imports System.ComponentModel Public Class Form1 Dim rdm As New Random() Dim ButtonOneClick As Boolean 'Make sure this is before all subs...

BackgroundWorker doesn't report progress when trying to send a loop of sms

c#,backgroundworker
I'm having a problem in using the BackgroundWorker while using a loop in sending sms, I want to return its progress in ProgressBar but I'm having an error "it doesn't report progress" private void btnSend_Click(object sender, EventArgs e) { backgroundWorker1.RunWorkerAsync(); comm.Close(); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { for...

How to pause ffmpeg than runs without window?

vb.net,ffmpeg,backgroundworker,sendkeys,pausing-execution
I'm working on a video converter and I wanted to be able to stop or pause ffmpeg by pressing a button. Googleing I have found a way but it's not working. basically I Start ffmpeg on a background worker in this way: Private Sub bw_DoWork(ByVal sender As Object, ByVal e...

Start background thread on form load

c#,multithreading,winforms,backgroundworker
Need to ask you for help as I'm struggling with this for too long now. Have gone over many tutorials but ended up with... nothing. So, I have a ServiceProcess class with GetServicesToList(). This method populates Service object with list of services. What I'm doing now, I'm reading a cache...

Does cron job block the main process or nodejs will create a worker to do cron task

node.js,process,cron,backgroundworker,cron-task
I am using node-cron to do some heavy tasks (update database) every minute. Does this task use main process to work or nodejs will create some workers to do these taks? var CronJob = require('cron').CronJob; new CronJob('0 * * * * *', function() { //Update database every minute here console.log('Update...

Separate Worker Role vs Windows Service alongside Another Role

c#,azure,backgroundworker
Windows Service Applications are useful to create long running applications that have their own sessions. They are useful to run in the background without interfering the main (or line-of-business) applications. The way to run these applications on Azure can be done alongside the actual roles by having start up task...

Images not appearing on WPF form when loading asynchronously

c#,wpf,multithreading,listbox,backgroundworker
I'm attempting to display (in a ListBox with a custom DataTemplate) a series of BitmapSource frames (thumbnails) extracted from a multi-page tiff image. When I process the tiff on the UI thread, and either directly add the images to a listbox's item collection or add them to a bound ObservableCollection,...

Cannot access form handle from within BackgroundWorker

c#,.net,multithreading,backgroundworker
I'm experiencing something weird. I can access many of my form's controls from within my BackgroundWorker DoWork method, but trying to get the Handle property on any of them will give me "Cross-thread operation not valid". For example: private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { var usefulText = textbox1.Text; var...

BackgroundWorkers - ProgressChanged for static progress

vb.net,multithreading,backgroundworker
I want to use a backgroundworker to poll a hardware sensor very frequently without leaving my UI inoperable. Because the backgroundworker simply polls until interrupted - runtime is purely dictated by the user interrupting it - it has no change in progress so to speak. If I call ReportProgress with...

Background Worker Running Twice on bw_DoWork() and bw_ProgressChanged() when using textBox1.AppendText()

c#,backgroundworker
I'm using Visual Studio 2013 and I can't figure out why the bw_ProgressChanged() runs twice when I use the textBox1.AppendText(). Also the bw_DoWork() runs twice. The code is just a copy paste from the Microsoft example with the difference that I'm using textBox1.AppendText() instead of textBox1.Text = "". The code...

C# BackgroundWorker and Invoke

c#,.net,multithreading,backgroundworker,invoke
Can someone explain why invoking Thread.Sleep from BackgroundWorker blocks its execution. Invoke should cause the delegate to be executed on the UI thread and background thread should continue with execution. But that does not happen - why? public partial class Form1 : Form { public Form1() { InitializeComponent(); BackgroundWorker bgrw...

C# appliction background worker - Thread.Sleep stops UI

c#,backgroundworker,sleep
I'm making a C# app to monitor some stuff in SQL. I use a background worker to pick up SQL data then build some charts based on the data. Pretty basic. However there's one frustrating thing about this. Using Thread.Sleep in the worker completely locks up the UI. No loading...

“Operation already completed” error when using Progress Bar

c#,wpf,progress-bar,backgroundworker
I currently have the following: View Model MovieProcessor movieProcessor = new MovieProcessor(SelectedPath, this); BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += movieProcessor.processMovie_DoWork; worker.ProgressChanged += worker_ProgressChanged; progressBar.Show(); worker.RunWorkerAsync(); worker_ProgressChanged void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { CurrentProgress = e.ProgressPercentage; } In my MovieProcessor class, I have the method...

Application.Wait or Thread.Sleep

c#,multithreading,backgroundworker
I am already using backgroundworker.RunAsyn() to run my code on a separate thread. However I am hitting a portion where the code iterates to the next line before the previous line is completed. Should I create a separate backgroundworker to handle that? Or should I use Application.Wait() or Thread.Sleep() I...

Background worker does not Work WPF [Solved]

c#,wpf,backgroundworker
In my WPF program it took huge processing time and freezing for long time. so I decided to use background worker and process it in background. but it does not work. through debug, the program stop at Render3D(). It does not throw exception. Its like when you put return. In...

C# - Listbox not updated when an entry is added to the list in a seperate thread

c#,multithreading,listbox,backgroundworker
I have a static class that print logs to the listbox so I can use it globally, and so I used a global instance of BindingList that was defined in my cls_globalvariables static class. I bound the BindingList to the UI's listbox in the UI constructor. public static class cls_globalvariables...

How do I update a Label from within a BackgroundWorker thread?

c#,wpf,xaml,backgroundworker
When I used WinForms, I would have done this in my bg_DoWork method: status.Invoke(new Action(() => { status.Content = e.ToString(); })); status.Invoke(new Action(() => { status.Refresh(); })); However in my WPF application I get an error saying that Invoke does not exist for Label. Any help would be appreciated....

Handling exceptions in asynchronous socket callbacks

c#,sockets,exception-handling,backgroundworker
I've been trying to get my head wrapped around socket communications and I've put together a small Windows Forms application as a test. This is basically a client that will connect to a server, send some bytes and disconnect. Ultimately, I'll receive a response from the server, too, but I've...

Progress Bar for reading a file - unexpected UI behavior

wpf,progress-bar,backgroundworker
I am trying to update a progress bar while reading a file. The file size will vary between 200Kb up to 50Mb. I am using System.ComponentModel.BackgroundWorker for the reading process, with these definitions: progressBar.Minimum = 0 progressBar.Maximum = System.IO.FileInfo.Length (I don't care about percentages). The reading process: void worker_DoWork(object sender,...

Thread sleeping in a BackgroundWorker

c#,wpf,multithreading,backgroundworker,thread-sleep
I wrote a simple app that adds 100000 lines of "Hello World" to a list using a BackgroundWorker. Below is the code of the work that my backgroundworker is doing in a separate thread: private void BgWorkerOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs) { int min = 0; foreach (var hw in hwList)...

Log BackgroundWorker activity in a different class from the MainWindow

c#,wpf,backgroundworker
I am using BackgroundWorker in some class (let's say "class A"). Now, from my MainWindow I call a function in this class that uses this BW. How can I put some text in a TextBox that belongs to the MainWindow?...

Adding items to a ListBox in a parallel way

c#,wpf,listbox,task-parallel-library,backgroundworker
I'm writing a simple application (for testing purposes) that adds 10 M elements to a ListBox. I'm using a BackgroundWorker to do the work and a ProgressBar control to display the progress. Each element is a just a "Hello World!" string with and index that I'm adding during the process....

Winforms background worker gets stuck

c#,winforms,backgroundworker
I am trying to build a simple code that joins csv files into one distinct file, but my background worker seems to have a mind of its own and my code gets stuck every time. Here is my code for joining the file using the background worker: private void backgroundWorker_DoWork(object...

Unhandled exceptions and background workers

.net,exception-handling,backgroundworker
In our application we use several background workers which are executed using SERVICENAME__bgw.RunWorkerAsync() where SERVICENAME is one of several different background worker processes executed by different timers. We recently saw this error message that was shown after an unhandled error bubbled up to the top of the call stack: My...

Limit number of backgroundworkers to two and complete jobs as they are added

c#,wpf,queue,backgroundworker
I currently have a treeview whereby the treeView items are bound to an ICommand interface that gets called when item selection is changed as follows: private ICommand _TreeviewSelectedItemChanged; public ICommand TreeviewSelectedItemChanged { get { if (_TreeviewSelectedItemChanged == null) { _TreeviewSelectedItemChanged = new DelegateCommand(delegate() { foreach (TreeViewClass tree in treeViewObsCollection) {...

I'm using backgroundworker and getting: InvalidOperationException: Cross-thread operation not valid how should i handle it?

c#,.net,multithreading,winforms,backgroundworker
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { Bitmap newbmp = new Bitmap(512, 512); IEnumerable<Point> CommonList = null; StreamWriter w = new StreamWriter(@"c:\diff\diff.txt"); pixelscoordinatesinrectangle = new List<Point>(); pixelscoordinatesinrectangle = pointsAffected.ToList(); DrawIt = false; for (int i = 0; i < trackBar1FileInfo.Length; i++) { DrawIt = true; this.BeginInvoke(new MethodInvoker(delegate { trackBar1.Value =...

Looking for explaination System.NotSupportedException

c#,wpf,backgroundworker,observablecollection,dispatcher
So first some code, question in the end. I've got some objects called machines, they have two properties public Logs MachineLogs { get { return _logs; } set { _logs = value; NotifyPropertyChanged ("MachineLogs"); } } public ObservableCollection<Part> Parts { get { return _parts; } set { _parts = value;...

Backgroundworker to stop work after specified time

c#,multithreading,timer,backgroundworker,stopwatch
I have went over dozens of question and tutorial but ended up with nothing so I hope to get help of you guys. I have a BW, doing some heavy work (rading up services, saving them into a file). BW is initialized at run time, and fired up with button...

C# SetPropertyThreadSafe vs Invoke thread-safe calls

c#,.net,multithreading,backgroundworker,invoke
Which of these two methods are better to update the UI from another thread? (for me they work both, but which is safer?) I would prefer the SetPropertyThreadSafe method as it needs less code. 1. label1.SetPropertyThreadSafe(() => this.label1.Text, "New Value"); 2. if (label1.InvokeRequired) { label1.Invoke(new MethodInvoker(delegate { label1.Text="New Value"; }));...

Implement responsive gui with sleep without backgroundworker

c#,multithreading,user-interface,backgroundworker,invoke
I have this code, which holds a Sleep. Gui doesn't response well, although Invoke. When I did it with backgroundWorker, then the Gui responses well. Can this be done only with backgroundWorker? and if so, then why. Thank you. private void button1_Click(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem((_) => F()); }...

Simplifying anonymous methods for background worker

c#,delegates,backgroundworker,anonymous-function
I am attempting to make all my code from button clicks, run in a background worker. So I have the following template of code. BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += delegate { //code }; backgroundWorker.RunWorkerAsync(); while (backgroundWorker.IsBusy) { Application.DoEvents(); } Just want to know if there is a way...

Should data being used by ActiveJob (resque) be persisted or put into a ruby object and passed by object id?

ruby-on-rails,backgroundworker,twilio,resque,rails-activejob
I am using Twilio to send/receive texts in a Rails 4.2 app. I am sending in bulk, around 1000 at a time, and receiving sporadically. Currently when I receive a text I save it to the DB (to, from, body) and then pass that record to an ActiveJob worker to...

Background worker RunWorkCompleted Event

c#,wpf,multithreading,backgroundworker
I have following wpf program, what i want to do is btnAnalyzer_click method to wait till both of the DoWork & RunWorkerCompleted methods finish. So i used a AutoResetEvent, but now bwAnalyze_click method(#4 line) run after the DoWork and then WorkerCompleted method(line order - #1 #2 #4 & #3). But...

Incomplete Controller Action job handle

asp.net,model-view-controller,backgroundworker
I am working on a asp.net mvc project .From my app i have to export certain entities to another app. what i do is 1) I export certain entities on a button click 2) after successful export i mark those entities as exported Now the question is what if before...

Why can an Exception not be rethrown in the BackgroundWorker RunWorkerCompleted event

c#,asynchronous,exception-handling,backgroundworker
I've checked through some posts on this topic which cover how to get around this issues, but I can't quite understand the Why of this odd behaviour? Short version: Why is are Exceptions thrown inside the RunWorkerCompleted event not caught by the calling code? Detailed version: I have a BackgroundWorker...

Background Worker for a big SQL query

c#,sql,backgroundworker,framework3.5
I have a big SELECT statement and it takes a little while to show the info. I want to know if it's possible to run the SELECT statement (or any SQL query for that matter) on a background worker in C# and show "something" to the user to them know...

Reuse backgroundworker in a for loop

c#,backgroundworker
I want to reuse a backgroudworker MAX_RUNS times. I use the following code: BackgroundWorker backgroundWorker1 = new BackgroundWorker(); backgroundWorker1.WorkerReportsProgress = true; backgroundWorker1.WorkerSupportsCancellation = true; for (int run =1; run <=MAX_RUNS; run++) { backgroundWorker1.DoWork += (s, args) => { // Time consuming DLL call }; backgroundWorker1.ProgressChanged += backgroundWorker1_ProgressChanged; backgroundWorker1.RunWorkerCompleted += backgroundWorker1_RunWorkerCompleted;...