Accelerator keys don't works in new AppDomain

Bars for Windows Forms Forum

Posted 13 years ago by Gianni Gardini - Italy
Version: 2.0.0073
Environment: Windows XP (32-bit)
Avatar
If you create a form with barManager in a new AppDomain, accelerator keys don't work.

For example, open a form with something like that:

        private void AppDomainBarMdiMergeParentForm()
        {
            BarMdiMergeParentForm f;
            System.Guid guid = System.Guid.NewGuid();
            AppDomain domain = AppDomain.CreateDomain(guid.ToString());

            Type type = typeof(BarMdiMergeParentForm);
            string assemblyName = type.Assembly.GetName().Name;
            string typeName = type.FullName;
            f = (BarMdiMergeParentForm) domain.CreateInstanceAndUnwrap(assemblyName, typeName);

            Application.DoEvents();

            f.Show();
        }
To duplicate the bug, using my LauncherForm.cs, launch "Bar Controls (MdiMerging)".
Then press "Alt+F": it doesn't work.

I'll send you a sample.

[Modified at 10/23/2006 05:09 AM]

Comments (3)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The problem here seems to be that for whatever reason, message filters on non-default AppDomains don't work and we use an IMessageFilter for tracking keypresses.

I've done a lot of searching on the Internet for if it's possible but have not seen anything that helps. Here is some simple LauncherForm test code (basically is your code plus several other things) that shows the bug in the .NET framework:
private void AppDomainBarMdiMergeParentForm()
{
    TestForm f;
    System.Guid guid = System.Guid.NewGuid();
    AppDomain domain = AppDomain.CreateDomain("Test domain: " + guid.ToString());

    Type type = typeof(TestForm);
    string assemblyName = type.Assembly.GetName().Name;
    string typeName = type.FullName;
    f = (TestForm) domain.CreateInstanceAndUnwrap(assemblyName, typeName);

    Application.DoEvents();

    f.Show();
}

private class TestForm : BarMdiMergeParentForm {
    public TestForm() {
        Console.WriteLine(AppDomain.CurrentDomain.FriendlyName);
        Application.AddMessageFilter(new MyMessageFilter());
    }
}
    
private class MyMessageFilter : IMessageFilter {

    bool IMessageFilter.PreFilterMessage(ref Message m) {
        Console.WriteLine(m.Msg);
        return false;
    }
}
I'm not sure what we can do if there's no way we can intercept the messages from the application message pump into the other AppDomain.

If you (or anyone else) find a way to get this working, please let us know. As the code stands now, the message filter is registered but PreFilterMessage is never called. If you replace the code in AppDomainBarMdiMergeParentForm to simply create a TestForm and show it in the default AppDomain, it works fine.


Actipro Software Support

Posted 13 years ago by Gianni Gardini - Italy
Avatar
If I create a new message pump in the new AppDomain, the menu seems to work.
You can test
Application.MessageLoop == true
to know if you have a message loop in the current thread/AppDomain.

So it's not a real bug of UIStudio, but may be you can help someone else adding that in Documentation Know Issues.

        private void AppDomainBarMdiMergeParentForm()
        {

            System.Threading.ThreadStart threadStart = new System.Threading.ThreadStart(CreateFormInOtherAppDomain);
            System.Threading.Thread t = new System.Threading.Thread(threadStart);
            t.Start();
            Application.DoEvents();
        }

        private void CreateFormInOtherAppDomain()
        {
            TestForm f;
            System.Guid guid = System.Guid.NewGuid();
            AppDomain domain = AppDomain.CreateDomain("Test domain: " + guid.ToString());

            Type type = typeof(TestForm);
            string assemblyName = type.Assembly.GetName().Name;
            string typeName = type.FullName;
            f = (TestForm) domain.CreateInstanceAndUnwrap(assemblyName, typeName);
            f.Run();
        }

        private class TestForm : BarMdiMergeParentForm 
        {
            public TestForm() 
            {
                System.Diagnostics.Debug.WriteLine("Running on " + AppDomain.CurrentDomain.FriendlyName);
            }

            //This form run in a new AppDomain: create a new Message Pump
            public void Run()
            {
                Application.Run(this);
            }

        }
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Good find... we'll add this info to the Known Issues topic.


Actipro Software Support

The latest build of this product (v2020.1 build 0400) was released 7 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.