frm.show()挂起应用程序 [英] frm.show() hangs the application

查看:91
本文介绍了frm.show()挂起应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个包含三个模块的文件转换,测试和编辑的应用程序.应用程序可以很好地处理一两个流,如

第一个流程:转换>>>测试>>编辑
第二流程:测试>>编辑

但是在执行完该流程之后,该应用程序就挂在了测试"模块中.它不会引发任何错误.我调试了代码,发现它挂在frm.Show()的调用上.

请帮忙.


谢谢和问候,
贾亚·乔希

代码是:

Hi,

i have an application which has three modules Conversion,testing and editing of a file. Application works fine for one or two flow like

1st flow: Conversion>>testing>>editing
2nd flow : testing>>editing

But after that flow, the application get hanged in "Testing" module. It does not throw any error. I debug the code and find that it hangs at the call of frm.Show().

Please help.


Thanks and Regards,
Jaya Joshi

Code Is:

private void trDashBoard_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            try
            {
                TreeView tree = (TreeView)sender;
                TreeViewItem trvItem = ((TreeViewItem)tree.SelectedItem);
                if (trvItem == null)
                    return;
                if (trvItem.Tag.ToString() == "ADMINISTRATOR" || trvItem.Tag.ToString() == "PROOF READER" || trvItem.Tag.ToString() == "CONVERTOR" || trvItem.Tag.ToString() == "EDITOR")
                    return;
                else
                {
                    TreeViewItem trparent = ((TreeViewItem)trvItem.Parent);
                    if (trparent.Tag.ToString() == "PROOF READER")
                    {
                        Testing frm = new Testing(trvItem.Tag.ToString(),true);
                        frm.Owner = this.Owner;
                        frm.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
                   
                        frm.Top =this.Top ;
                       frm.Left = this.Left;
                       System.Threading.Thread.Sleep(500);
                        frm.Show();
                        this.Close();
                    }
                    else if (trparent.Tag.ToString() == "EDITOR")
                    {
                        Editor frmEdit = new Editor(trvItem.Tag.ToString(),true);
                        frmEdit.Owner = this.Owner;
                        frmEdit.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
                        frmEdit.Top = this.Top;
                        frmEdit.Left = this.Left;
                        frmEdit.Show();                        
                       this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Application Error. /n"+ ex.Message+ "/n" + ex.Source  + "/n" +ex.StackTrace);
            }
        }

推荐答案



我认为您的问题是您的代码无法正常工作..

Hi

I think your problem is your code not work properly see here..

报价:

System.Threading.Thread.Sleep(500);
frm.Show();
this.Close();
}
否则,如果(trparent.Tag.ToString()=="EDITOR")
{
编辑器frmEdit = new Editor(trvItem.Tag.ToString(),true);
frmEdit.Owner = this.Owner;
frmEdit.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
frmEdit.Top = this.Top;
frmEdit.Left = this.Left;
frmEdit.Show();
this.Close();

System.Threading.Thread.Sleep(500);
frm.Show();
this.Close();
}
else if (trparent.Tag.ToString() == "EDITOR")
{
Editor frmEdit = new Editor(trvItem.Tag.ToString(),true);
frmEdit.Owner = this.Owner;
frmEdit.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
frmEdit.Top = this.Top;
frmEdit.Left = this.Left;
frmEdit.Show();
this.Close();



在哪里使用 System.Threading.Thread.Sleep(500);
它不执行上层代码..所以尝试调用一个停止函数,如..



hi in that where use System.Threading.Thread.Sleep(500);
it not execute upper code..so try to call one stop function Like..

Public Void Stop()
{
 System.Threading.Thread.Sleep(500);
}



并调用它而不是Thread.Sleep().

它可以正常工作...



and call this instead of Thread.Sleep().

IT works...




我一直尝试相同的方法(在表单而不是wpf上,但是大多数是相同的),但确实在这里找到了一个小问题;

首先设置

Hi,

I''ve been giving the same a try (on forms rather than wpf but most is the same) and did find one small issue here;

first you set

报价:

Editor frmEdit = new Editor(trvItem.Tag.ToString(),true);
frmEdit.Owner = this.Owner;

Editor frmEdit = new Editor(trvItem.Tag.ToString(),true);
frmEdit.Owner = this.Owner;



然后几行:



then a couple of lines later:

报价:

this.Close();

this.Close();



如果关闭表单的所有者,则可能会毁了它的一天...
如果您不想再见到所有者,我建议您将其隐藏.

如果我做对了,让我知道,否则,我会花更多的时间在它上

干杯,

AT



If you close the owner of the form you kind of ruin its day...
If you don''t wat to see the owner anymore I suggest that you hide it.

Let me know if I got it right, if not i''ll spend a bit more time on it

Cheers,

AT




使用单例模式可以解决我的问题.

隐藏窗体而不是关闭窗体/窗口.仅当应用程序关闭时,窗口才会关闭.

谢谢和问候,
贾亚·乔希(Jaya Joshi)
Hi,

My problem get resolved using singleton pattern.

Instead of closing the forms/Window, hide the form. The windows are closed only when application is closing.

Thanks and Regards,
Jaya Joshi


这篇关于frm.show()挂起应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆