vendredi 18 avril 2014

Windows xp - c#: « System.InvalidOperationException : file d'attente vide "et autres erreurs lors de l'utilisation SendKey.SendWait() - Stack Overflow


I wrote a program to send 'Enter' key to a certain active window. I used a Timer to get the title of the active window for the moment and act accordingly. I made an error log file so i can keep track of all the errors. Here's the code that's creating the error:


    private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
try
{
ttl = GetActiveWindowTitle();
if (ttl != null)
{
if (ttl.ToLower() == "xxxxxxxxxxx")
{
SendKeys.SendWait("{ENTER}");
}
}
}
catch (Exception err)
{
Write2ErrLog(err, "OnTimedEvent");
}
}

Here's the GetActiveWindowTitle() method.


    static private string GetActiveWindowTitle()
{
try
{
const int nChars = 256;
IntPtr handle = IntPtr.Zero;
StringBuilder Buff = new StringBuilder(nChars);
handle = GetForegroundWindow();

if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
}
catch (Exception e)
{
Write2ErrLog(e, "GetActiveWindowTitle");
return null;
}
}

Here are the errors I am receiving:



4/19/2011 12:57:16 PM: System.InvalidOperationException: Queue empty.
at System.Collections.Queue.Dequeue()
at System.Windows.Forms.SendKeys.SendInput(Byte[] oldKeyboardState, Queue previousEvents)
at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
at System.Windows.Forms.SendKeys.SendWait(String keys)
at DataViews_SendKeys.Form1.OnTimedEvent(Object source, ElapsedEventArgs e) OnTimedEvent

4/19/2011 1:03:11 PM: System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Queue.Clone()
at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
at System.Windows.Forms.SendKeys.SendWait(String keys)
at DataViews_SendKeys.Form1.OnTimedEvent(Object source, ElapsedEventArgs e) OnTimedEvent

4/19/2011 1:04:00 PM: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.SendKeys.Flush()
at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
at System.Windows.Forms.SendKeys.SendWait(String keys)
at DataViews_SendKeys.Form1.OnTimedEvent(Object source, ElapsedEventArgs e) OnTimedEvent

I should mention that, the computer I'm running this program on is a HP server computer with Intel Xeon processor and the OS is Windows XP. The program runs without an error on my laptop, but not on the server computer. Any thoughts?



I wrote a program to send 'Enter' key to a certain active window. I used a Timer to get the title of the active window for the moment and act accordingly. I made an error log file so i can keep track of all the errors. Here's the code that's creating the error:


    private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
try
{
ttl = GetActiveWindowTitle();
if (ttl != null)
{
if (ttl.ToLower() == "xxxxxxxxxxx")
{
SendKeys.SendWait("{ENTER}");
}
}
}
catch (Exception err)
{
Write2ErrLog(err, "OnTimedEvent");
}
}

Here's the GetActiveWindowTitle() method.


    static private string GetActiveWindowTitle()
{
try
{
const int nChars = 256;
IntPtr handle = IntPtr.Zero;
StringBuilder Buff = new StringBuilder(nChars);
handle = GetForegroundWindow();

if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
}
catch (Exception e)
{
Write2ErrLog(e, "GetActiveWindowTitle");
return null;
}
}

Here are the errors I am receiving:



4/19/2011 12:57:16 PM: System.InvalidOperationException: Queue empty.
at System.Collections.Queue.Dequeue()
at System.Windows.Forms.SendKeys.SendInput(Byte[] oldKeyboardState, Queue previousEvents)
at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
at System.Windows.Forms.SendKeys.SendWait(String keys)
at DataViews_SendKeys.Form1.OnTimedEvent(Object source, ElapsedEventArgs e) OnTimedEvent

4/19/2011 1:03:11 PM: System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Queue.Clone()
at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
at System.Windows.Forms.SendKeys.SendWait(String keys)
at DataViews_SendKeys.Form1.OnTimedEvent(Object source, ElapsedEventArgs e) OnTimedEvent

4/19/2011 1:04:00 PM: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.SendKeys.Flush()
at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
at System.Windows.Forms.SendKeys.SendWait(String keys)
at DataViews_SendKeys.Form1.OnTimedEvent(Object source, ElapsedEventArgs e) OnTimedEvent

I should mention that, the computer I'm running this program on is a HP server computer with Intel Xeon processor and the OS is Windows XP. The program runs without an error on my laptop, but not on the server computer. Any thoughts?


0 commentaires:

Enregistrer un commentaire