backgroundworker

Using BackgroundWorker to update the UI without freezes…?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 13:47:41
问题 I have the following code for population a ListView from a background thread (DoWork calls the PopulateThread method): delegate void PopulateThreadCallBack(DoWorkEventArgs e); private void PopulateThread(DoWorkEventArgs e) { if (this.InvokeRequired) { PopulateThreadCallBack d = new PopulateThreadCallBack(this.PopulateThread); this.Invoke(d, new object[] { e }); } else { // Ensure there is some data if (this.DataCollection == null) { return; } this.Hide(); // Filter the collection based on the

Updating background worker to async-await

ぃ、小莉子 提交于 2019-12-04 11:07:58
问题 So this is how I currently use background worker to save a lot of stuff to file while presenting the user with a progress bar and preventing any changes to the UI while saving is in progress. I think I've captured the essential features. The modal ProgressWindow displays a progress bar and not much else. How would I go about changing this to async-await pattern, if I had to? private ProgressForm ProgressWindow { get; set; } /// <summary>On clicking save button, save stuff to file</summary>

Passing Values To and From Background Worker

☆樱花仙子☆ 提交于 2019-12-04 11:07:30
I'm a self-taught novice experimenting with the Rijndael encryption algorithm , I've previously got it to work very well, but since trying to get the encryption to run on a background worker to free-up the the form for the user I've ran into numerous issues. Firstly I tried just placing the byval's I used in my previous code into the background worker, but I got an error with it not being compatible -- Specifically the ByVal Direction As CryptoAction . So to be clear, I was trying something like this: Private Sub bw_DoWork(ByVal sender As Object,ByVal strInputFile As String, ByVal

How to use BackGroundWorker in class file?

纵然是瞬间 提交于 2019-12-04 09:23:02
My program.cs calls the mdi parent frmMain. frmMain then opens different child forms based on user action. All the processing logic is written in BusinessLogic.cs. frmMain at load calls the methods of BusinessLogic.cs to initially populate the data. The child forms too call BusinessLogic to fetch data and process it. I'd like to do all this through a BackGroundWorker ie the frmMain calls the (say) StartBGWorker() method of BusinessLogic.cs and this method creates a backgroundworker for this specific call, calls the Do_work event, does the fetching & processing and closes when done. I'm at a

BackgroundWorker with anonymous methods?

六眼飞鱼酱① 提交于 2019-12-04 08:51:58
问题 I'm gonna create a BackgroundWorker with an anonymous method. I've written the following code : BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += new DoWorkEventHandler( () => { int i = 0; foreach (var item in query2) { .... .... } } ); But Delegate 'System.ComponentModel.DoWorkEventHandler' does not take '0' arguments and I have to pass two objects to the anonymous method : object sender, DoWorkEventArgs e Could you please guide me, how I can do it ? Thanks. 回答1: You just need to

WPF/BackgroundWorker and BitmapSource problem

十年热恋 提交于 2019-12-04 07:43:08
I am a beginner with WPF and trying a home project to become familiar with the technology. I have a simple form where the user selects an image file, I then display EXIF data along with a thumbnail of the image. This is working fine but when I select a RAW image file (~9 MB) there can be a slight delay while the thumb loads, so I thought I could use the BackgroundWorker to decode the image and the user can view the EXIF data, then when the image has been decoded it is displayed. The BitmapSource object is declared in the BackgroundWorkers DoWork method: worker.DoWork += delegate(object s,

How to run a background thread in ruby?

南笙酒味 提交于 2019-12-04 07:29:05
I am new to ruby and thought it would be a great idea to rebuild a simple chat program I made in C#. I am using Ruby 2.0.0 MRI (Matz’s Ruby Implementation). The problem is I want to have I/O for simple server commands while the server is running. This is the server that was taken from the sample. I added the commands method that uses gets() to get input. I want this method to run as a thread in the background, but the thread is blocking the other thread. require 'socket' # Get sockets from stdlib server = TCPServer.open(2000) # Socket to listen on port 2000 def commands x = 1 while x == 1

How can I scan and transfer images from a document feeder asynchronously

萝らか妹 提交于 2019-12-04 07:23:52
Which parts of the communication with TWAIN can be put into another thread, e.g. a BackgroundWorker? Or: Is it possible to split the loop that handles the image transfer? Some scanner drivers scan all images before returning to the calling application which forces the application to handle all images at once. This results in e.g. OutOfMemoryException or weird behavior in my WPF application when suddenly all events (raised after every scanned image) have to be handled at once. Additionally the application hangs until the transfer was completed. I am using TwainDotNet: http://code.google.com/p

WPF Dispatcher Invoke return value is always null

青春壹個敷衍的年華 提交于 2019-12-04 06:25:31
I have a call to a method that returns a UIElement that I call using the Dispatcher , below is the code. However the return value of the Dispatcher invoke is always NULL, any ideas? void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { var slides = (IList<UIElement>)e.Argument; var bmpSlides = new List<UIElement>(); var imageService = new ImageService(); int count = 0; foreach (UIElement slide in slides) { object retVal = slide.Dispatcher.Invoke( new ThreadStart(() => imageService.GenerateProxyImage(slide))); bmpSlides.Add(imageService.GenerateProxyImage(slide)); _backgroundWorker

Why does backgroundworker lags or freezes for a bit when waiting for page to load on webbrowser?

谁说胖子不能爱 提交于 2019-12-04 05:54:35
问题 I'm running a backgroundworker for my webbrowser on a winform, it works and all, but why does the UI lags or freezes for a moment to wait for the page to load when I want it to load in the background so that the UI is fully functional? Private Property pageready As Boolean = False Public Sub WaitForPageLoad() AddHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter) While Not pageready Application.DoEvents() End While pageready = False End Sub