Программа работает только в том случае, если messagebox находится в коде
I have been working on a game in my free time for a while now. The game is a continuum of Histacom. Below is the code I am using to start a program in the game. The process is started with the exepath and arguments passed. The thread pauses for a half second to allow the new process to start. Then SetParent() grabs the process's MainWindowHandle and puts the process inside of a panel on the form. I then have the thread pause again for 5 seconds (this will be reduced). Finally the form is resized to fit the new process's main window. The code works fine as long as I have that Message-box in, but if I comment it out then the process won't go inside the panel or execute the rest of the code. The code works fine on my desktop, but not my tablet, which is slower. So is it that I need to pause more and configure something based on the computers specs or something else? If you need any clarification, just comment.
Спасибо за ваше время
Что я уже пробовал:
Public Sub New(ByRef exePath As String, ByRef argurment As String) InitializeComponent() Dim info As ProcessStartInfo = New ProcessStartInfo(exePath, argurment) info.UseShellExecute = False info.CreateNoWindow = True info.RedirectStandardInput = False info.RedirectStandardOutput = False info.RedirectStandardError = False 'info.WindowStyle = ProcessWindowStyle.Hidden pro = System.Diagnostics.Process.Start(info) Try run: System.Threading.Thread.Sleep(500) SetParent(pro.MainWindowHandle, Me.panGuestMod.Handle) '<DllImport("user32.dll")> Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr End Function Nap(5000, False) 'Pauses program for 5 sec 'MessageBox.Show("Program only works if this message box is uncommented") GetClientRect(pro.MainWindowHandle, siz) '<DllImport("user32.dll")> Private Shared Function GetClientRect(ByVal HWND As IntPtr, ByRef LPRECT As Rectangle) As Boolean End Function me.Size = New Size(siz.Width, siz.Height) Catch ex As Exception MessageBox.Show(ex.ToString) GoTo run End Try End Sub