logo
down
shadow

Modifiing ItemsSource within BackgroundWorker Causes an Exception


Modifiing ItemsSource within BackgroundWorker Causes an Exception

By : user2952210
Date : November 19 2020, 12:41 AM
I wish did fix the issue. Set the BackgroundWorker.WorkerSupportProgress to True and attach the ProgressChangedEvent. Replace your ReceiveNotification method with ReportProgress calls to update the UI. The ProgressChangedEventHandler is marshalling to the UI thread, so no invokerequired.
code :


Share : facebook icon twitter icon
how to pause a backgroundworker thread in case of exception and resume it if exception occurs

how to pause a backgroundworker thread in case of exception and resume it if exception occurs


By : Weedmantas
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further im using following code to send sms to all the students in the database , try this
code :
private void btnsend_Click(object sender, EventArgs e)
    {
        foreach (Control c in Controls)
        {
            c.Enabled = false;
        }
        if (!bgw.IsBusy)
        {
            bgw.RunWorkerAsync();
        }
    }
    private void bgw_DoWork(object sender, DoWorkEventArgs e)
    {
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if ((bgw.CancellationPending == true))
            {

                e.Cancel = true;
                break;
            }
            else
            {
                Invoke((MethodInvoker)delegate()
                {
                    using (var sp = new SerialPort(cbcomport.Text))
                    {
                        try
                        {
                            sp.Open();
                            sp.WriteLine("AT" + Environment.NewLine);
                            sp.WriteLine("AT+CMGF=1" + Environment.NewLine);
                            sp.WriteLine("AT+CMGS=\"" + dt.Rows[i]["PhoneNo"] + "\"" + Environment.NewLine);
                            sp.WriteLine(tbsms.Text + (char)26);
                            if (sp.BytesToRead > 0)
                            {
                                tbsentto.Text = i + 1 + " of " + dt.Rows.Count;
                            }
                            Thread.Sleep(5000);
                        }
                        catch (Exception ex)
                        {
                            if (MessageBox.Show(ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Retry)
                            {
                                try
                                {
                                    sp.Open();
                                    sp.WriteLine("AT" + Environment.NewLine);
                                    sp.WriteLine("AT+CMGF=1" + Environment.NewLine);
                                    sp.WriteLine("AT+CMGS=\"" + dt.Rows[i]["PhoneNo"] + "\"" + Environment.NewLine);
                                    sp.WriteLine(tbsms.Text + (char)26);
                                    if (sp.BytesToRead > 0)
                                    {
                                        tbsentto.Text = i + 1 + " of " + dt.Rows.Count;
                                    }
                                    Thread.Sleep(5000);
                                }
                                catch (Exception ex2)
                                {
                                    MessageBox.Show(ex2.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    bgw.CancelAsync();

                                }
                            }
                            else
                            {
                                bgw.CancelAsync();
                            }
                        }
                    }
                });
            }
        }
    }
    private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        foreach (Control c in Controls)
        {
            c.Enabled = true;
        }
    }
BackgroundWorker starts other threads that have an exception. Exception not caught?

BackgroundWorker starts other threads that have an exception. Exception not caught?


By : Vlad Ryzhkov
Date : March 29 2020, 07:55 AM
like below fixes the issue The Backgroundworker is setup as an async method. I believe this is causing the RunWorkerCompleted event to fire before the DoWork event has completed and the exception has been raised. By updating the DoWork method to remove the async compiler keyword and removing any awaits the exception propogates back to the method specified by the RunWorkerCompleted event and e.Error != null
C# modifiing Excel files, keeping the style

C# modifiing Excel files, keeping the style


By : Charlie Niel Celiz
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I would recommend using the OpenXML SDK from Microsoft. It allows you to do about anything with the newer xlsx files (Excel 2007 and up) using C#.
OpenXML SDK for Office
OutOfMemory Exception using backgroundworker on C# : works fine without backgroundworker

OutOfMemory Exception using backgroundworker on C# : works fine without backgroundworker


By : leonardodavinci
Date : March 29 2020, 07:55 AM
will be helpful for those in need It appears that the answer was that I was calling bgw.ReportProgress((int)percentComplete); far too often --- changing the code so it only reports every few percent seems to have fixed the issue.
python - reading file, modifiing it and saving, but it is saved with no modifications. why?

python - reading file, modifiing it and saving, but it is saved with no modifications. why?


By : user2336720
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I have files in this format: 01, 02, ... 10, 11, 12, ... They are all html and i was trying to parse them a little. But when i tried to do it, and save the files, it did happen, but with no changes.
code :
r.replace('<br>', '/n')
r.replace('"', '/"')
sub('<[^<]*>', '', r) # delete all <tags>
sub('<\/[^<]*>', '', r) # delete all </tags>
r = r.replace('<br>', '/n')
r = r.replace('"', '/"')
r = sub('<[^<]*>', '', r) # delete all <tags>
r = sub('<\/[^<]*>', '', r) # delete all </tags>
Related Posts Related Posts :
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • Using same alias for multiple namespaces
  • how to move mails into separate folders
  • Multithreaded Uploader
  • Memory fragmentation?
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • Marshal.Copy attempted to read or write protected memory At Random Times
  • Restrict Type variable to specific class or subclass
  • Horizontal text alignment in a PdfPCell
  • C# crashing with Form.show() command, ObjectDisposedException - Deeper look / explanation please
  • Will the result of a LINQ query always be guaranteed to be in the correct order?
  • "Could not find default endpoint element that references contract"
  • Umbraco Request.QueryString is null if it's the first time the page is loaded
  • Error inconsistent accessibility method C#
  • How to program Intel Xeon Phi with C#?
  • remove nested element using regular expression
  • Is there a C# alternative to Java's vararg parameters?
  • Clear particular column values in DataTable
  • how to add event handler to programatically created checkboxes
  • Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'
  • Check for key in pre-existing dictionary in case insensitive manner
  • How to remove year from datetime object?
  • Accessing Settings in different ways
  • "This project is empty" error in Sonarqube
  • How to create reusable icon menu in Xamarin
  • Value Cannot be null in Ado.Net connectivity
  • Adding a custom/dynamic attribute when using XSD.exe
  • How to convert object to correct type
  • Automatically sign out from Forms Authentication in ASP.NET when browser is closed
  • Can a WCF service support both Buffered and Streamed transfer modes?
  • Verify a CA Certificate with a public key in C#
  • How to invoke a Web Service that requires the "patch" verb using the C# WebClient wrapper?
  • Proper way a implementing property based on generic type
  • Closing a form that is created in another thread
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org