Alex
Alex

Reputation: 11137

Error Creating window handle

I've written a client-server c# app and let it run all night , and when i wanted to see if it was still working i've found an error on the server . unfortunately the app is to big to paste in some code, but i get an error at

Application.Run(form1)

in the program.cs that says alt text

The first two messageboxes can be ignored (from left to right ) because they are supposed to show , but the other

delegate buton couldn't be executed

comes from this code ánd mai have a part in this error(this code is in form1.cs) :

public void setButonState(inout_buton b, bool t, int q,int contor)
        {
            try
            {
                if (b.InvokeRequired)
                {
                    Callback d = new Callback(setButonState);
                    this.Invoke(d, new object[] { b, t, q, contor });
                }
                else
                {
                    b.Enabled = t;
                    if (q == 0) b.setBackgroundGrey();
                    if (q == 1) b.setBackgroundGreen();
                    if (q == 2) b.setBackgroundRed();
                    if (q == 3) b.setBackgroundOrange();

                    b.setSecondaryLabel(contor);

                }
            }
            catch { new ShowMessageBox("FORM1 : delegate buton couldn't be executed"); }

        }

My question is : in what conditions does these errors show ?

Upvotes: 1

Views: 5116

Answers (3)

bandonian
bandonian

Reputation: 11

I was receiving this same error when calling a static classes method from within a foreach statement. The User Objects count continued to increase and was not released until the program ended or the error occurred.

I changed the static method into an instance method and the User Object stayed at 60.

//created and instance of the object
var oIP = new ImportProvider();

foreach(var patient in lstPatients)
{
    var oP = PatientConversionProvider.GetPatient(oPatient.RecordId);

    if(oP != null)
    {

        //referenced the instance member (changed from a static member)
        if(oIP.ImportDataIntoSmartRx(oP))
        {
            successCount++;
            lstMrNumber.Add(oPatient.MrNumber);
        }

        totalCount++;

...

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 941605

Diagnose this with Taskmgr.exe, Processes tab. View + Select Columns and tick USER objects. Observe this value for your process while it runs. It should be steadily climbing. When it reaches 10,000 then your program will bomb with this exception.

This is caused by not calling Dispose() on controls that you remove from the Controls collection yourself, either by calling Remove() or Clear().

Upvotes: 10

George Johnston
George Johnston

Reputation: 32258

Sounds to me like your application is trying to access protected data. Keep in mind, when your system locks due to inactivity/logging off, your application will not be able to interact with certain aspects of the system. Such an example would be trying to grab the handle of a window or take a screen shot. These will both throw errors.

Upvotes: 1

Related Questions