等待表单在执行长进程时消失了 [英] waiting form get disappeared while executing long process

查看:93
本文介绍了等待表单在执行长进程时消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示等待消息,该消息实际上是一个表单,而长进程正在某个不同的文件中运行。我正面临的问题是,一旦流程开始,表格就会消失,但它仍处于活动状态且正在运行流程



我的代码:

< pre lang =vb> Dim objWait As New frmWaitupdate
Dim strReply As String

Dim ischange as Boolean
Dim obj1 As MyBO.UpdateSchemaBO()
ischange = obj1.CheckSchemaChanges(Application.ProductVersion.ToString())

If ischange = True 然后

lblMsg.Text = 发现架构更改请稍候。请等待。

obj1.AddVersionTable(Application.ProductVersion .ToString())
.Visible = True

strReply = obj1.UpdateSchema( Me
如果 strReply<> 然后
MessageBox .Show(strReply, abc
Else
MessageBox.Show( 架构已成功更新 abc
结束 < span class =code-keyword>如果


' objWait.Hide()
ElseIf ischange = False 然后

MessageBox.Show( No schema发现更改 abc


结束 如果

结束 如果



当进程进入UpdateSchema()时需要大约30-45秒才能完成表单消失。有什么方法可以保持表单在屏幕上完好无损直到我的进程完成?

解决方案

您的问题是您的长时间运行的代码在UI(启动)线程上运行并阻止处理任何Windows消息,例如WM_PAINT会导致您的窗口重新绘制。



您的解决方案是将长时间运行的代码移动到后台线程。您可以通过多种不同的方式执行此操作,例如使用Thread类,任务并行库,BackgroundWorker(建议!)组件,或者您拥有的内容。


I am trying to display waiting message which is actually a form while long process is running in some different file. Issue i am facing is the form get disappeared once the process gets started but its still active and running the process

My code:

Dim objWait As New frmWaitupdate
   Dim strReply As String

   Dim ischange As Boolean
   Dim obj1 As New MyBO.UpdateSchemaBO()
   ischange = obj1.CheckSchemaChanges(Application.ProductVersion.ToString())

   If ischange = True Then

       lblMsg.Text = "Schema changes found please wait  Please wait."

       obj1.AddVersionTable(Application.ProductVersion.ToString())
       Me.Visible = True

       strReply = obj1.UpdateSchema(Me)
       If strReply <> "" Then
           MessageBox.Show(strReply, "abc")
       Else
           MessageBox.Show("Schema updated successfully", "abc")
       End If


       'objWait.Hide()
   ElseIf ischange = False Then

       MessageBox.Show("No schema changes found", "abc")


       End If

   End If


As the process goes in UpdateSchema() which takes around 30-45 sec to finish the form gets disappear.Is there any way to keep the form intact on screen until my process gets complete??

解决方案

Your problem is that your long-running code is running on the UI (startup) thread and preventing any windows messages from being processed, like WM_PAINT which causes your windows to repaint themselves.

Your solution is to move the long-running code to a background thread. You can do this in a number of different ways, like using the Thread class, the Task Parallel Library, the BackgroundWorker (suggested!) component, or what have you.


这篇关于等待表单在执行长进程时消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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