首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

Winform 一个程序打开除此而外一个程序闪退

2013-07-20 
Winform 一个程序打开另外一个程序闪退我有两个应用程序都是用C#写的,假如程序为A和B。我首先将A运行起来,

Winform 一个程序打开另外一个程序闪退
我有两个应用程序都是用C#写的,假如程序为A和B。我首先将A运行起来,点击A界面上的某一个按钮,将B程序打开,代码如下:

//获取要运行的程序路径
strFilePath = Application.StartupPath + "\" + strFilePath;
                if (File.Exists(strFilePath))
                {
                    //声明一个程序信息类
                    System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();

                    //设置外部程序名
                    Info.FileName = strFilePath;

                    //设置外部程序的启动参数(命令行参数)为test.txt
                    Info.Arguments = YHInfo.czyId.ToString() + " " + YHInfo.czyMm.Trim();

                    //声明一个程序类
                    System.Diagnostics.Process Proc;
                    try
                    {
                        //启动外部程序
                        Proc = System.Diagnostics.Process.Start(Info);
                        if (!lstSysName.Contains(Proc.ProcessName.Trim()))
                        {
                            lstSysName.Add(Proc.ProcessName.Trim());
                        }


                    }
                    catch (System.ComponentModel.Win32Exception ex)
                    {
                        ComTools.ShowMsg("系统找不到指定的程序文件。" + ex.Message.ToString(), 3);
                        return;
                    }
                }
                else
                {
                    ComTools.ShowMsg("系统找不到指定的程序文件。", 3);
                    return;
                }


通过A调起B时,B闪的一下就退出了,经过一步一步排查,发现,只要在B程序中使用了背景图片,就会退出,将B程序启动界面的背景图片去掉运行正常,点击B中某一个带背景的窗体,和个B应用程序退出。如果单独运行B程序没有问题。


在多台电脑上测试无问题,但买了一批联想机器20台左右安装了3台都是同样问题  对于此问题比较费解  不知道有没有人遇到过。

查看系统日志有错误信息,如下:
事件类型:错误
事件来源:.NET Runtime
事件种类:无
事件 ID:1026
日期:2013-7-15
事件:21:57:21
用户:N/A
计算机:WWW-13EB274504B
描述:
Application: 营养订餐.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
   at System.Drawing.SafeNativeMethods+Gdip.GdipDrawImageRectRectI(System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, System.Runtime.InteropServices.HandleRef, DrawImageAbort, System.Runtime.InteropServices.HandleRef)
   at System.Drawing.Graphics.DrawImage(System.Drawing.Image, System.Drawing.Rectangle, Int32, Int32, Int32, Int32, System.Drawing.GraphicsUnit, System.Drawing.Imaging.ImageAttributes, DrawImageAbort, IntPtr)


   at System.Drawing.Graphics.DrawImage(System.Drawing.Image, System.Drawing.Rectangle, Int32, Int32, Int32, Int32, System.Drawing.GraphicsUnit, System.Drawing.Imaging.ImageAttributes)
   at System.Windows.Forms.ControlPaint.DrawBackgroundImage(System.Drawing.Graphics, System.Drawing.Image, System.Drawing.Color, System.Windows.Forms.ImageLayout, System.Drawing.Rectangle, System.Drawing.Rectangle, System.Drawing.Point, System.Windows.Forms.RightToLeft)
   at System.Windows.Forms.Control.PaintBackground(System.Windows.Forms.PaintEventArgs, System.Drawing.Rectangle, System.Drawing.Color, System.Drawing.Point)
   at System.Windows.Forms.Control.PaintBackground(System.Windows.Forms.PaintEventArgs, System.Drawing.Rectangle)
   at System.Windows.Forms.Control.OnPaintBackground(System.Windows.Forms.PaintEventArgs)
   at System.Windows.Forms.ScrollableControl.OnPaintBackground(System.Windows.Forms.PaintEventArgs)
   at System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs, Int16)
   at System.Windows.Forms.Control.WmEraseBkgnd(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.ScrollableControl.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
   at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32, System.String, System.String, Int32, Int32, Int32, Int32, Int32, System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, System.Object)
   at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32, System.String, System.String, Int32, Int32, Int32, Int32, Int32, System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, System.Runtime.InteropServices.HandleRef, System.Object)
   at System.Windows.Forms.NativeWindow.CreateHandle(System.Windows.Forms.CreateParams)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Control.CreateControl(Boolean)
   at System.Windows.Forms.Control.CreateControl()


   at System.Windows.Forms.Control.OnVisibleChanged(System.EventArgs)
   at System.Windows.Forms.ScrollableControl.OnVisibleChanged(System.EventArgs)
   at System.Windows.Forms.Control.OnParentVisibleChanged(System.EventArgs)
   at System.Windows.Forms.Control.OnVisibleChanged(System.EventArgs)
   at System.Windows.Forms.ScrollableControl.OnVisibleChanged(System.EventArgs)
   at System.Windows.Forms.Form.OnVisibleChanged(System.EventArgs)
   at System.Windows.Forms.Control.SetVisibleCore(Boolean)
   at System.Windows.Forms.Form.SetVisibleCore(Boolean)
   at System.Windows.Forms.Control.set_Visible(Boolean)
   at System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
   at System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
   at System.Windows.Forms.Application.Run(System.Windows.Forms.Form)
   at YYDC.Program.Main(System.String[])

谁帮忙 分析一下什么原因。

调用图片的路径没有用绝对路径,请加上Application.StartPath 

[解决办法]
联想机器有独立显卡吗?
[解决办法]
咳咳 别做坏事啊
[解决办法]
在联想上运行就有问题,重装下系统,还有问题就把这批电脑卖了呗Winform 一个程序打开除此而外一个程序闪退
[解决办法]
你看看是不是因为相对Path 引发的问题。在某些机器上设置可以找到 在某些却无法找到。
[解决办法]
对背景图片部分做处理,确保这部分正常
[解决办法]
Winform 一个程序打开除此而外一个程序闪退路过

热点排行