.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Mutext Problem in C#-AutoCad

2 REPLIES 2
Reply
Message 1 of 3
soumen.r
407 Views, 2 Replies

Mutext Problem in C#-AutoCad

Hi All,

 

I have two classes in one dll named AcadPv.dll

AcadPv.cs (Entry Point)
frmAssignCode.cs (WinForm)



Code for AcadPv.cs
-----------------

       internal static Mutex mutexSINF = null;

        public void ShowInformation()
        {
            bool IsShowInformation = true;
            mutexSINF = new Mutex(false, "AcadPvShowInformation", out IsShowInformation);
            if (IsShowInformation == false)
            {
                mutexSINF.Close();
                return;
            }

            frmAssignCode fmAssignCode = new frmAssignCode();
            fmAssignCode.Tag = SHOW;
            fmAssignCode.Show();       //Ok ok I should call AutoDesk.AutoCad. bla bla bla . ShowModeless here
         }



Code for frmAssignCode (In the designer file the dispose method is like the following)
------------------------------------------------------------------------------------------------------

       protected override void Dispose(bool disposing)
        {
            if (disposing)
                if (AcadPv.mutexSINF != null)
                {
                    AcadPv.mutexSINF.Close();
                    AcadPv.mutexSINF = null;
                }
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

       private void btCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Close();
        }

Now the problem is
--------------------------

I am calling the AcadPv.dll from AutoCad. First time the Form "frmAssignCode" is opening fine. When the form is opened in the AutoCad if I want to reopen that form the form is not opening just as per the expectation (thats why I tried mutex here).
BUT
Once the form is closed (1st time) and I can not reopen the form, as "IsShowInformation" variable in "AcadPv.cs" file is always returning FALSE. Why? How to solve it?

 

Note

-----

 I can not use singleton as in "AcadPv.cs (Entry Point)" there are two mthods.

1. ShowInformation (code is given above)
2. StoreInformation

Both are calling same class "frmAssignCode.cs (WinForm)" with different setting and tag values. If I make "frmAssignCode.cs (WinForm)" singleton this type of architecture is not possible. I have to make separate forms for "ShowInformation" and "StoreInformation" though they will be more or less exactly same.

If I make "frmAssignCode.cs (WinForm)" singleton then both command "ShowInformation" & "StoreInformation" will invoke same instance of "frmAssignCode.cs (WinForm)" which is not desirable.



Please help,
Thanking you

 

Soumen

SRoy
2 REPLIES 2
Message 2 of 3

I am not sure why the mutex is not working… But I think you can resolve your issue using a “bool” variable.

 

static public bool bShowing = false;

 

[CommandMethod("TestShowDilaog")]

public void TestShowDilaog() // This method can have any name

{

    if (bShowing)

        return;

 

    bShowing = true;

    Form1 form = new Form1();

    Application.ShowModelessDialog(form);

}

 

In the form class, identify the form closing and reset the bool variable.

 

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

    Test.bShowing = false;

}

 

 

Virupaksha Aithal

Autodesk Developer Network



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 3 of 3

Yes I can achieve that in that way, and as a matter of fact I am doing in that way already right now. But I wonder why mutex is not working.

 

Thanx

SRoy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost