backgroundworker

Background worker class and passing messages using progress events from a different class in c#

假装没事ソ 提交于 2019-12-02 12:34:16
问题 So i have one class which starts a new class in a new background worker, and the background worker passes status messages back using the progresschanged section. When i try and and use this by typing classname.Dataworker.reportprogress(5) from a seperate class i get an error that I am using an object before definition. The examples I have found all use a single class and different functions within that. It may be a stupid easy mistake but i just can't see it, thanks for any help you can give!

Background Worker implementation

若如初见. 提交于 2019-12-02 11:47:16
This is my background work DoWor function, is the implementation taking into consideration the GUI operation done okay? private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { try { string connectionString = "Data Source=LPMSW09000012JD\\SQLEXPRESS;Initial Catalog=Pharmacies;Integrated Security=True"; SqlConnection con = new SqlConnection(connectionString); con.Open(); string query = "SELECT * FROM dbo.Liguanea_Lane2"; SqlCommand cmd = new SqlCommand(query, con); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { string scode = dr.GetString(dr

How to queue up delegates to be executed in series in the background with C#?

谁说我不能喝 提交于 2019-12-02 11:30:01
From a game loop i want to start work in the background that should be executed one after another but should not block the game loop. So ideally a class BackgroundQueue that could be used like this: BackgroundQueue myQueue = new BackgroundQueue(); //game loop called 60 times per second void Update() { if (somethingHappens) { myQueue.Enqueue(() => MethodThatTakesLong(someArguments)) } } Is there a ready made class in .NET that works for the scenario? Or does someone know a good example on how to implement the BackgroundQueue class? A nice to have would be if the class could report whether it's

Freeing resources when thread is not alive

最后都变了- 提交于 2019-12-02 10:36:22
问题 I am using BackgroundWorker and inside it I am using foreach loop, inside which i create new thread, wait for it to finish, and than report progress and continue foreach loop. Here is what I am talking about: private void DoWork(object sender, DoWorkEventArgs e) { var fileCounter = Convert.ToDecimal(fileNames.Count()); decimal i = 0; foreach (var file in fileNames) { i++; var generator = new Generator(assembly); var thread = new Thread(new ThreadStart( delegate() { generator.Generate(file); }

Convert a WPF dispatcher to Winforms BGworker?

筅森魡賤 提交于 2019-12-02 09:51:44
i recently acquired some source code for a console wrapper for a server. The program was originaly in WPF and part of the code was: private void ServerProc_ErrorDataReceived(object sender, DataReceivedEventArgs e) { Dispatcher.Invoke(new Action(() => { ConsoleTextBlock.Text += e.Data + "\r\n"; ConsoleScroll.ScrollToEnd(); })); } private void ServerProc_OutputDataReceived(object sender, DataReceivedEventArgs e) { Dispatcher.Invoke(new Action(() => { ConsoleTextBlock.Text += e.Data + "\r\n"; ConsoleScroll.ScrollToEnd(); ParseServerInput(e.Data); })); } Its also had this annotation in both voids:

How to use Ping.SendAsync working with datagridview?

天涯浪子 提交于 2019-12-02 09:48:10
I have an application that pings every IP in the datagridview in order to compile a list of responsive IP RoundtripTime.When finished the step,I will push the RoundtripTime back to datagridview. ... foreach (DataGridViewRow row in this.gvServersList.Rows) { this.current_row = row; string ip = row.Cells["ipaddr_hide"].Value.ToString(); ping = new Ping(); ping.PingCompleted += new PingCompletedEventHandler(ping_PingCompleted); ping.SendAsync(ip, 1000); System.Threading.Thread.Sleep(5); } ... private static void ping_PingCompleted(object sender, PingCompletedEventArgs e) { var reply = e.Reply;

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

岁酱吖の 提交于 2019-12-02 09:01:48
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 Public Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) If

Cross thread operation not valid in BackgroundWorker

江枫思渺然 提交于 2019-12-02 07:33:45
I want to display some data on form load in a data gridview , the data which i want to display is in large number of rows , when i use background worker processor it show me the following error. My code: private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { try { FTPUtility obj = new FTPUtility(); dataGridViewRequest.DataSource = obj.ListRequestFiles(); dataGridViewRequest.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewRequest.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewRequest.Columns[2].AutoSizeMode =

Stopping background worker

痞子三分冷 提交于 2019-12-02 06:50:38
问题 My app uses background worker to go do some work inside a loop. I have it so that at each loop iteration, it checks if cancellation pending is true and if it is, breaks out the loop. All OK, my app stops processing once it is finished the current iteration of the loop. The problem is that I think the background worker is still running - if I click the button to start processing again, I get an error saying the background worker is busy. I was going to dispose of the worker but then it is

Run code in Background Worker

不打扰是莪最后的温柔 提交于 2019-12-02 06:22:35
I am trying to work with asp.net. I have very small question. In one of my button click event, I have heavy task that need to be executed and it causing problem. How can i run this code in background worker. Any hint will be appreciated as i have no played with this background worker yet. Here is the code for my background worker. protected void green_button_Click(object sender, EventArgs e) { string stdOut = null; string stdError = null; string address = "192.168.1.88"; string user = "user"; string pass = "testuser"; SshExec ssh = new SshExec(address, user, pass); green_output.Text =