Why is while(UC.Isloading()); causing a crash?

If you have a question about the software please ask it here.

Why is while(UC.Isloading()); causing a crash?

Postby Dan911 » Wed Oct 31, 2018 1:28 am

Hi Balazs
I normally use the most recent released version and use Net.4 versions just for testing but I just loaded my plugin in 1.2106 and UCCNC stop responding on loading a file. After some debugging I determined the cause was the while(UC.Isloading()); and once removed plugin worked fine. I'm almost certain I tested this in a net 4 version but with 1.2105 and 1.2106 it stopped responding and catch ignored. In 1.2049 no trouble with the while isloading function.

I can't imagine it being a problem with my code...lol but here it is to check.

Code: Select all
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            { percent.Text = "Aborted"; MessageBox.Show(this, "Conversion Aborted","Unit Converter Message"); }

            else
            {
                 MessageBox.Show(this, "Conversion Complete", "Unit Converter Message");

                try
                {
                    UC.Loadfile(WizPath +Filename + ".tap");
                    //while(UC.IsLoading()){}
                 }
                catch (Exception) { MessageBox.Show("Exception"); }
            }

            percent.Text = "";
            progressBar1.Value = 0;
        }
Dan911
 
Posts: 502
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Why is while(UC.Isloading()); causing a crash?

Postby dezsoe » Wed Oct 31, 2018 9:00 am

Hi Dan,

I also had some trouble with IsLoading (many versions before) and since then I open the file in a separate thread without any problem:

Code: Select all
        Dim thrDoOpenFile As New Thread(Sub() UC.Loadfile(sFileName))
        thrDoOpenFile.CurrentCulture = Thread.CurrentThread.CurrentCulture
        thrDoOpenFile.Start()
        While UC.IsLoading
            UC.Wait(10)
            Application.DoEvents()
        End While
dezsoe
 
Posts: 594
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Why is while(UC.Isloading()); causing a crash?

Postby Dan911 » Wed Oct 31, 2018 9:15 pm

Thanks Dezsoe, I will be utilizing your code for future. Any idea the version this problem started? Seems odd UCCNC would leave a function that would cause program to stop responding.

Thanks again,
Dan
Dan911
 
Posts: 502
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Why is while(UC.Isloading()); causing a crash?

Postby cncdrive » Wed Oct 31, 2018 9:25 pm

The isloading function can't cause such problems.
This is all the code in the isloading function:

public bool IsLoading()
{
Thread.Sleep(50);
return fileloading;
}

As you can see it simply returns a value of a variable, the function does not do anything else.
cncdrive
Site Admin
 
Posts: 2363
Joined: Tue Aug 12, 2014 11:17 pm

Re: Why is while(UC.Isloading()); causing a crash?

Postby Dan911 » Wed Oct 31, 2018 9:34 pm

Hi Balazs, That's why I posted code to help make sense what's happening. Only thing I know for sure is this didn't happen in net 2 verisions and early net 4. Loaded plugin in 1.2106 and UCCNC stopped responding, removed while is loading and worked as expected.

Dan
Dan911
 
Posts: 502
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Why is while(UC.Isloading()); causing a crash?

Postby Dan911 » Wed Oct 31, 2018 9:44 pm

A little more info.........
The plugin completes it's task, when the stop responding occurs is "generating Gcode".
Dan911
 
Posts: 502
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Why is while(UC.Isloading()); causing a crash?

Postby cncdrive » Wed Oct 31, 2018 10:35 pm

You are probably calling the Loadfile method from the main thread and somehow an interlock occurs.
If you created your background worker from the UI thread then the Completed event will be rised on the UI thread!
Try to create a thread and run your code from there.
cncdrive
Site Admin
 
Posts: 2363
Joined: Tue Aug 12, 2014 11:17 pm

Re: Why is while(UC.Isloading()); causing a crash?

Postby dezsoe » Wed Oct 31, 2018 11:34 pm

Hi Dan,

It is not .Net dependent. I had my issue more than 2 years ago: my oldest backup of this file is from 08 2016 and it already has the thread. (And UC.Loadfile in comment.)
dezsoe
 
Posts: 594
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Why is while(UC.Isloading()); causing a crash?

Postby Dan911 » Thu Nov 01, 2018 1:32 am

Thanks Dezsoe your solution worked well, starting to see clearly of cause.
Dan911
 
Posts: 502
Joined: Mon Oct 31, 2016 1:22 am
Location: USA


Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 7 guests