Windows form ??

Hi,
I have a question regarding Windows form application. My application has to implement a feature which is similar to Excel. Here is what Excel does:-

I launch two instances of Excel. In each instance I open up the same file. While opening a file in the second instance Excel gives me a choice to be notified when the file becomes available for read/write, I select OK and it opens the file in readonly mode. Then In readonly instance I go and select cell format dialog and leave that instance keeping dialog open. Then I go to the first instance which opened the file in readwrite mode and close the file and the instance also. Then in the second instance I keep format dialog open and do some changes. Once I close the dialog Excel notifies that file is available for readwrite.

In my Windows application if I bring up the modal dialog I can receive event behind that file is available. But I don't know how I will detect that modal dialog is being displayed or if I know then when to tell the user that file is available for readwrite mode. Because modal dialog does not block message loop, so I don't think I have to post a message. I am not getting how to do it.


Thanks in advance
KDV




Answer this question

Windows form ??

  • vitfrasson

    Let us take a simple scenario. In Windows form I registered to one of the event which is fired from Business logic in a different thread (not GUI thread). Let us say that I have opened up a modal dialog in Windows form . While the dialog is being displayed that event comes up. In the handler I want to make sure that no modal dialog is displayed in the Windows form. How to check that. It is like deferring the work to be done in the event handler untill dialog disappears.

    Thanks

    KDV



  • Sean Riddle

    Thanks. I will try this

  • gmitchell7

    Its hard to understand what exactly you need.

    if you are reffering to watching file changes, check out the

    System.IO.FileSystemWatcher

    this class gives events on file\directiory changes.

    If you want something else, let us know.



  • GordonBeMe

    I think that you could create some static method to use when ever calling ShowDialog:

    public static DialogResult ShowDialog(Form frm)

    {

    DialogResult result = frm.ShowDialog();

    CheckForPendingEvents();

    return result;

    }

    I don't know any method like this one on 1.1



  • BMcK

    Thanks. So I will use second option (static method) for time being untill I upgrade my project to .NET 2.0

    KDV



  • Amaltea

    OK, I got it now.

    IMHO, you should implement something like this:

    void event_Handler(object sender, EventArgs e)

    {

    bool doSomethingNow = true;

    foreach (Form frm in Application.OpenForms)

    {

    if (frm.Modal)

    {

    doSomethingNow = false;

    break;

    // Delay the command to do something

    }

    }

    if (doSomethingNow)

    {

    // Do something

    }

    else

    {

    // Try again later

    }

    }

    Make sense

    About how to detect that Model is closing, try:

    Application.LeaveThreadModal event.



  • patmur

    Application.LeaveThreadModal is available only in .NET 2.0 Is there something similar available in .NET 1.1

  • Windows form ??