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
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
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