locked
Simulate key being held down. RRS feed

  • Question

  • Well i've been trying to make something run with a lot less code(and faster) but it seems with SendKeys some things are getting lost(or discarded) by the program, its only the arrow keys as I try & make it complete a pre-defined maze to see how fast it can be completed.

    If I use SendKeys("RIGHT 8") for example the maze usually only moves a few times, sometimes maybe only 1.

    Also I looked up how to hold a key down/simulate it but it's not working for the arrow keys(untested on other keys).

    The only way i've made it work is delays, decently delayed like 200ms & it's a huge maze but if i hold a key manually I can go much faster yet sendkeys method can't go that fast using individual presses this is why I want to simulate a holding down action.

    Anyone have xample code?

    ---Please it must be working xample code I can make it work for my purpose if it works like on button click, etc....but I tried copying full (supposedly working) codes before & they never worked for me/my key, so please help me with a full working code xample cause i've looked & tried hard(with only failing results).


    MORE INFO:Also I tried SendKeys.SendWait() which is meant to wait for keystrokes to be processed & that didn't help either so my best guess is the keystrokes are processed but discarded(like a movement delay code that doesn't queue movements but rather ignores extra movements)
    • Edited by Maya Key Monday, September 5, 2011 7:52 AM
    Monday, September 5, 2011 7:48 AM

Answers

  • For a simple, controlled situation like this where you can define the target application to receive the keystrokes, and you can define/control the user interaction between the applications (that is, you know you will start sending keystrokes, watch the other application, then stop sending or change the key being sent according to your observations; there will be no other interaction with the computer while this process is being carried out), then the SendInput windows API call is probably the best way to achieve your desired result.

    SendInput is a simple way to simulate any kind of input messages for the currently active windows application.  This basically allows you to simulate a mouse, keyboard, or other hardware input device and send input to Windows.  Windows then worries about determining what application should receive this input, based on whatever application is currently active.

    Since .Net will easily let us activate any other running application, this greatly simplifies our native Windows interaction because all we need to do is tell Windows that the computer has generated new input; we do not have to worry about how to route that message to our desired target application.

    There should be lots of example out there for using SendInput; one I found quickly is at:
    http://www.pinvoke.net/default.aspx/user32.SendInput

    It as from this article that I pulled the type definitions for the unmanged com structures used in the following code example.  I would suggest doing more research on SendInput in order to better understand how the sample below works.

    The following example is a very simple implementation meant to be easy to follow.  I have written it in such a way that you should be able to start a new Windows Forms Application project, paste this code over the default Form1 code, start Notepad (notepad must be running for the sample to work), and then Run the project.

    This will let you see an example of "holding down the 'a' key" in Notepad.  You should then be able to follow the comments to change the example to send "right arrow" to your maze game.  Here is a tip, the name of the maze game needed by the code can be found in the Task Manager under the Processes tab.  It will be the value in the Image Name column, which is the file name of the process - you want the part before the extension (.exe for example).

    Here is the code:

    ''' <summary>
    ''' Provides an example of simulating keyboard input.
    ''' Input will be sent to the active application.
    ''' This example wants to use Notepad as the active application,
    ''' so be sure to start Notepad before you run this example.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Form1
        'Create a button used to run the example
        Private WithEvents _StartButton As New Button
        'Create a simple timer used to send keystrokes repeatedly
        Private WithEvents _RunTimer As New Timer
    
        'Declare a Process variable to hold a reference
        ' to the application which should receive keystrokes.
        ' This allows our program to ensure that the proper
        ' target application is active before starting to
        ' send the keystrokes.
        Private _TargetApplication As Process
    
        'Declare a byte variable to hold the value of the
        ' virtual keycode to send. The keycode is technically
        ' a UShort, but only values of 0 - 254 are acceptable,
        ' so we use a Byte.
        ' The example will send the key "a" (&H42) to notepad, but this
        ' could be changed to "right arrow" (&H27).
        ' Valid keycodes can be found here: http://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx
        Private _VirtualKeyToSend As Byte
    
        'Setup the example on Form.Load:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Setup the test button
            _StartButton.AutoSize = True
            _StartButton.Text = "Start"
            Controls.Add(_StartButton)
            'Setup the timer; 10ms should be plenty fast enough
            _RunTimer.Interval = 10
            'Get a reference to the target application;
            ' you can change "notepad" to the name of your maze game
            Dim notepads() As Process = Process.GetProcessesByName("notepad")
            _TargetApplication = notepads(0)
            'Set the keycode value to send to the target application
            ' This example is sending "a" (&H42) but you can change it
            ' to send "right arrow" by setting the value to &H27.
            _VirtualKeyToSend = &H42
        End Sub
    
        'Toggle sending keystrokes on/off when the button is clicked:
        Private Sub _StartButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _StartButton.Click
            If _RunTimer.Enabled Then
                _StartButton.Text = "Start"
                _RunTimer.Stop()
            Else
                _StartButton.Text = "Stop"
                'Make sure our target application is the active window
                AppActivate(_TargetApplication.Id)
                _RunTimer.Start()
            End If
        End Sub
    
        'Send a keystroke when the timer ticks:
        Private Sub _RunTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles _RunTimer.Tick
            KeystrokeSimulator.SendKeystrokeToActiveApplication(&H41)
        End Sub
    End Class
    
    ''' <summary>
    ''' A bare-bones implementation of the Win32 SendInput function.
    ''' Sends simulated keyboard characters to the active application window.
    ''' </summary>
    ''' <remarks>
    ''' Win32 Com object wrapper definitions take from: http://www.pinvoke.net/default.aspx/user32.SendInput
    ''' Additional information can be found at: http://msdn.microsoft.com/en-us/library/ms646310(v=VS.85).aspx
    ''' </remarks>
    Public Class KeystrokeSimulator
        Private Declare Function SendInput Lib "user32.dll" Alias "SendInput" (ByVal nInputs As UInteger, ByVal pInputs() As INPUT, ByVal cbSize As Integer) As UInteger
    
        Private Shared _InputStructSize As Integer = System.Runtime.InteropServices.Marshal.SizeOf(New INPUT)
        Private Shared _InputMessage As New INPUT With {.type = 1}
    
        Public Shared Sub SendKeystrokeToActiveApplication(ByVal virtualKeyCode As Byte)
            _InputMessage.ki.wVk = CShort(virtualKeyCode)
            KeystrokeSimulator.SendInput(1, New INPUT() {_InputMessage}, _InputStructSize)
        End Sub
    
        <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit, pack:=1, Size:=28)> _
        Private Structure INPUT
            <System.Runtime.InteropServices.FieldOffset(0)> Public type As InputType
            <System.Runtime.InteropServices.FieldOffset(4)> Public mi As MOUSEINPUT
            <System.Runtime.InteropServices.FieldOffset(4)> Public ki As KEYBDINPUT
            <System.Runtime.InteropServices.FieldOffset(4)> Public hi As HARDWAREINPUT
        End Structure
    
        <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, pack:=1)> _
        Private Structure MOUSEINPUT
            Public dx As Int32
            Public dy As Int32
            Public mouseData As Int32
            Public dwFlags As MOUSEEVENTF
            Public time As Int32
            Public dwExtraInfo As IntPtr
        End Structure
    
        <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, pack:=1)> _
        Private Structure KEYBDINPUT
            Public wVk As Int16
            Public wScan As Int16
            Public dwFlags As KEYEVENTF
            Public time As Int32
            Public dwExtraInfo As IntPtr
        End Structure
    
        <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, pack:=1)> _
        Private Structure HARDWAREINPUT
            Public uMsg As Int32
            Public wParamL As Int16
            Public wParamH As Int16
        End Structure
    
        Private Enum InputType As Integer
            Mouse = 0
            Keyboard = 1
            Hardware = 2
        End Enum
    
        <Flags()> _
        Private Enum MOUSEEVENTF As Integer
            MOVE = &H1
            LEFTDOWN = &H2
            LEFTUP = &H4
            RIGHTDOWN = &H8
            RIGHTUP = &H10
            MIDDLEDOWN = &H20
            MIDDLEUP = &H40
            XDOWN = &H80
            XUP = &H100
            VIRTUALDESK = &H400
            WHEEL = &H800
            ABSOLUTE = &H8000
        End Enum
    
        <Flags()> _
        Private Enum KEYEVENTF As Integer
            EXTENDEDKEY = 1
            KEYUP = 2
            [UNICODE] = 4
            SCANCODE = 8
        End Enum
    End Class
    

    Hope this helps!


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    • Marked as answer by Maya Key Monday, September 5, 2011 9:30 PM
    • Unmarked as answer by Maya Key Monday, September 5, 2011 10:13 PM
    • Proposed as answer by Mike Feng Thursday, September 8, 2011 11:57 AM
    • Marked as answer by Mike Feng Wednesday, September 14, 2011 7:22 AM
    Monday, September 5, 2011 5:58 PM

All replies

  • Simulating a key being held down can be simulated by creating a switch (boolean value) which is set to false when the key event key up is handled again.

    If you want to repeat this, you use therefore a timer.


    Success
    Cor
    Monday, September 5, 2011 7:54 AM
  • I don't understand what you are wanting me to do but in my somewhat rambling of a post maybe you didn't understand, I want to simulate keydown of the right arrow key & have tried lots of different codes to attempt this but all attempts have failed.

    I am not trying to detect when a key is down or how long it has been held, I want to control another program(by holding a directional arrow down) so that I can make this maze complete itself, when using sendkeys/other methods the delay between movement is big but holding down a key in-game lets you move faster.

    Monday, September 5, 2011 8:12 AM
  • Michael,

    I get the idea that you want to simulate a feature of a keyboard on another program in your own program. So in my idea is this the same reply like I gave you but than even without that switch.

    Use a timer.

     


    Success
    Cor
    Monday, September 5, 2011 8:37 AM
  • You haven't indicated how you are using SendKeys to send multiple keys, but the correct way to do it is to send the multiple keys as a sequence of key codes using one SendKeys statement.  

    Is the problem specific to a particular operating system?  Sendkeys behaves differently depending on the OS.  In particular, with a newer operating system the Wait option doesn't do anything. You can force SendKeys to revert to its original behaviour (which might or might not help) by modifying the config file.
    http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx

    But whatever version is used, there can be timing issues.  That's unavoidable when communicating between processes in a system that tries to impose security.

    On of the published workarounds using the Windows API is probably the preferable way to do it.

    • Edited by Acamar Monday, September 5, 2011 8:49 AM
    Monday, September 5, 2011 8:48 AM
  • You aren't understanding because the other program(which is a maze game) that I am using SendKeys() to isn't another program of my own or another window in the same project, rather it's made by someone else with an unknown program(could be VB but probably not).

    As for how I am sending the keystrokes well no matter if I split them all up or put them in one statement some of the keystrokes I put in are being lost or discarded & are not always followed exactly(depending on the time delay between keystrokes).

    I was trying to make up for this by making a button be simulated as being held down because it should be faster(as it's faster physically holding the button on my keyboard)


    MORE INFO:I am using Windows 7 Ultimate 64-bit OS.
    • Edited by Maya Key Monday, September 5, 2011 2:41 PM
    Monday, September 5, 2011 2:38 PM
  • Michael,

    Who is You in your reply?. 

    I probably don't understand what you are doing, but in the mean time I was replying Acamar has given another reply.

    I watch thread views in the forums while I think you are replying to Acamar.

    (Probably a better choice I've never used sendkeys, I only don't like it if I get the idea I'm playing on Internet and somebody has used it to cheat)


    Success
    Cor
    Monday, September 5, 2011 2:49 PM
  • For a simple, controlled situation like this where you can define the target application to receive the keystrokes, and you can define/control the user interaction between the applications (that is, you know you will start sending keystrokes, watch the other application, then stop sending or change the key being sent according to your observations; there will be no other interaction with the computer while this process is being carried out), then the SendInput windows API call is probably the best way to achieve your desired result.

    SendInput is a simple way to simulate any kind of input messages for the currently active windows application.  This basically allows you to simulate a mouse, keyboard, or other hardware input device and send input to Windows.  Windows then worries about determining what application should receive this input, based on whatever application is currently active.

    Since .Net will easily let us activate any other running application, this greatly simplifies our native Windows interaction because all we need to do is tell Windows that the computer has generated new input; we do not have to worry about how to route that message to our desired target application.

    There should be lots of example out there for using SendInput; one I found quickly is at:
    http://www.pinvoke.net/default.aspx/user32.SendInput

    It as from this article that I pulled the type definitions for the unmanged com structures used in the following code example.  I would suggest doing more research on SendInput in order to better understand how the sample below works.

    The following example is a very simple implementation meant to be easy to follow.  I have written it in such a way that you should be able to start a new Windows Forms Application project, paste this code over the default Form1 code, start Notepad (notepad must be running for the sample to work), and then Run the project.

    This will let you see an example of "holding down the 'a' key" in Notepad.  You should then be able to follow the comments to change the example to send "right arrow" to your maze game.  Here is a tip, the name of the maze game needed by the code can be found in the Task Manager under the Processes tab.  It will be the value in the Image Name column, which is the file name of the process - you want the part before the extension (.exe for example).

    Here is the code:

    ''' <summary>
    ''' Provides an example of simulating keyboard input.
    ''' Input will be sent to the active application.
    ''' This example wants to use Notepad as the active application,
    ''' so be sure to start Notepad before you run this example.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Form1
        'Create a button used to run the example
        Private WithEvents _StartButton As New Button
        'Create a simple timer used to send keystrokes repeatedly
        Private WithEvents _RunTimer As New Timer
    
        'Declare a Process variable to hold a reference
        ' to the application which should receive keystrokes.
        ' This allows our program to ensure that the proper
        ' target application is active before starting to
        ' send the keystrokes.
        Private _TargetApplication As Process
    
        'Declare a byte variable to hold the value of the
        ' virtual keycode to send. The keycode is technically
        ' a UShort, but only values of 0 - 254 are acceptable,
        ' so we use a Byte.
        ' The example will send the key "a" (&H42) to notepad, but this
        ' could be changed to "right arrow" (&H27).
        ' Valid keycodes can be found here: http://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx
        Private _VirtualKeyToSend As Byte
    
        'Setup the example on Form.Load:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Setup the test button
            _StartButton.AutoSize = True
            _StartButton.Text = "Start"
            Controls.Add(_StartButton)
            'Setup the timer; 10ms should be plenty fast enough
            _RunTimer.Interval = 10
            'Get a reference to the target application;
            ' you can change "notepad" to the name of your maze game
            Dim notepads() As Process = Process.GetProcessesByName("notepad")
            _TargetApplication = notepads(0)
            'Set the keycode value to send to the target application
            ' This example is sending "a" (&H42) but you can change it
            ' to send "right arrow" by setting the value to &H27.
            _VirtualKeyToSend = &H42
        End Sub
    
        'Toggle sending keystrokes on/off when the button is clicked:
        Private Sub _StartButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _StartButton.Click
            If _RunTimer.Enabled Then
                _StartButton.Text = "Start"
                _RunTimer.Stop()
            Else
                _StartButton.Text = "Stop"
                'Make sure our target application is the active window
                AppActivate(_TargetApplication.Id)
                _RunTimer.Start()
            End If
        End Sub
    
        'Send a keystroke when the timer ticks:
        Private Sub _RunTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles _RunTimer.Tick
            KeystrokeSimulator.SendKeystrokeToActiveApplication(&H41)
        End Sub
    End Class
    
    ''' <summary>
    ''' A bare-bones implementation of the Win32 SendInput function.
    ''' Sends simulated keyboard characters to the active application window.
    ''' </summary>
    ''' <remarks>
    ''' Win32 Com object wrapper definitions take from: http://www.pinvoke.net/default.aspx/user32.SendInput
    ''' Additional information can be found at: http://msdn.microsoft.com/en-us/library/ms646310(v=VS.85).aspx
    ''' </remarks>
    Public Class KeystrokeSimulator
        Private Declare Function SendInput Lib "user32.dll" Alias "SendInput" (ByVal nInputs As UInteger, ByVal pInputs() As INPUT, ByVal cbSize As Integer) As UInteger
    
        Private Shared _InputStructSize As Integer = System.Runtime.InteropServices.Marshal.SizeOf(New INPUT)
        Private Shared _InputMessage As New INPUT With {.type = 1}
    
        Public Shared Sub SendKeystrokeToActiveApplication(ByVal virtualKeyCode As Byte)
            _InputMessage.ki.wVk = CShort(virtualKeyCode)
            KeystrokeSimulator.SendInput(1, New INPUT() {_InputMessage}, _InputStructSize)
        End Sub
    
        <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit, pack:=1, Size:=28)> _
        Private Structure INPUT
            <System.Runtime.InteropServices.FieldOffset(0)> Public type As InputType
            <System.Runtime.InteropServices.FieldOffset(4)> Public mi As MOUSEINPUT
            <System.Runtime.InteropServices.FieldOffset(4)> Public ki As KEYBDINPUT
            <System.Runtime.InteropServices.FieldOffset(4)> Public hi As HARDWAREINPUT
        End Structure
    
        <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, pack:=1)> _
        Private Structure MOUSEINPUT
            Public dx As Int32
            Public dy As Int32
            Public mouseData As Int32
            Public dwFlags As MOUSEEVENTF
            Public time As Int32
            Public dwExtraInfo As IntPtr
        End Structure
    
        <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, pack:=1)> _
        Private Structure KEYBDINPUT
            Public wVk As Int16
            Public wScan As Int16
            Public dwFlags As KEYEVENTF
            Public time As Int32
            Public dwExtraInfo As IntPtr
        End Structure
    
        <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, pack:=1)> _
        Private Structure HARDWAREINPUT
            Public uMsg As Int32
            Public wParamL As Int16
            Public wParamH As Int16
        End Structure
    
        Private Enum InputType As Integer
            Mouse = 0
            Keyboard = 1
            Hardware = 2
        End Enum
    
        <Flags()> _
        Private Enum MOUSEEVENTF As Integer
            MOVE = &H1
            LEFTDOWN = &H2
            LEFTUP = &H4
            RIGHTDOWN = &H8
            RIGHTUP = &H10
            MIDDLEDOWN = &H20
            MIDDLEUP = &H40
            XDOWN = &H80
            XUP = &H100
            VIRTUALDESK = &H400
            WHEEL = &H800
            ABSOLUTE = &H8000
        End Enum
    
        <Flags()> _
        Private Enum KEYEVENTF As Integer
            EXTENDEDKEY = 1
            KEYUP = 2
            [UNICODE] = 4
            SCANCODE = 8
        End Enum
    End Class
    

    Hope this helps!


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    • Marked as answer by Maya Key Monday, September 5, 2011 9:30 PM
    • Unmarked as answer by Maya Key Monday, September 5, 2011 10:13 PM
    • Proposed as answer by Mike Feng Thursday, September 8, 2011 11:57 AM
    • Marked as answer by Mike Feng Wednesday, September 14, 2011 7:22 AM
    Monday, September 5, 2011 5:58 PM
  • It appears to be incredibly helpful & took almost no effort to make it do what I wanted with all arrow keys, I used code very similar to what your showing here with very little changes but I guess it was off by a small little bit(because my attempts would not repeat it correctly - it would do it once & stop(in the code I came up with). - but yours is working 100% for me where as my attempts had failed

    Thanks very much for your help as it was indeed very helpful. :)




    • Edited by Maya Key Monday, September 5, 2011 10:26 PM
    Monday, September 5, 2011 9:28 PM
  • Well yours was working for me but it actually slowed me down in the long run trying to mix sendkeys & that code, also the code seems to not so much as to hold it down as send it repeatedly using the SendInput method.

    Your code has the same type of timing issues as well & if I set my delay on SendKeys as fast as it can go without messing up (36ms) that way actually goes FASTER than this does & I changed the timer to 1ms just to see the effect, it doesn't go any faster than at 10ms, you may say its the game but if I hold it down manually it still goes faster anyways than this does(but obviously using windows repeat speed, which is apparentally really quick.

    Is there a way to make a key be held down, a code I can run & it will just simply in windows think its held down until I press the key(or possibly close the program) & not have a timer constantly calling to sendtopic?

    I thought SendTopic made it think it was held down & not on a timer-based key pressing system just like SendKeys is.

    Maybe I missed setting a variable or something? I got excited because it went faster(because I wasn't using the lowest possible delay without mistakes already when using SendKeys()

    Monday, September 5, 2011 10:24 PM
  • Well, you could try sending the keystrokes faster using a background thread instead of a timer, but you will still likely face timing issues and/or flood the application with input.

    I suppose then what you want to do is just send KeyDown and KeyUp messages directly to the maze program.  However, you will need to know what control is handling the key events...

    You'll  probably want to use:

        Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowW" (ByVal className As String, ByVal windowName As String) As IntPtr
        Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageW" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    
    

    Or PostMessage instead of SendMessage, to locate the window for the Maze game and then send it a keydown message (WM_KEYDOWN = &H100).

    However, the Maze game's window may not be the correct target; that is, you may need to locate a handle for a control inside the maze game's main window.

    Here are some links which may help:

    FindWindow info:
    http://www.pinvoke.net/default.aspx/user32.FindWindow
    http://msdn.microsoft.com/en-us/library/ms633499(v=VS.85).aspx

    SendMessage info:
    http://www.pinvoke.net/default.aspx/user32.SendMessage
    http://www.vbcode.com/Asp/showsn.asp?theID=11797
    http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx

    Related thread with C# solution to Notepad:
    http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/1dcae178-50e8-446f-9c45-f016ad0f7fc3

    You should be able to get this going with the API calls above, but it may take some work to figure out how to get your key messages routed to the maze game correctly (this is why a solution using SendInput is much easier to implement).

    Sorry the previous code didn't help so much... maybe this will do more for you.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    • Proposed as answer by Mike Feng Thursday, September 8, 2011 5:39 AM
    • Unproposed as answer by Mike Feng Thursday, September 8, 2011 6:14 AM
    Tuesday, September 6, 2011 2:37 PM
  • Well the other was a very decent way to do it the way I thought would definitely work better for me as I had come up with similar code to what you had except mine didn't work correctly, I really did think that's the way I needed (& it was helpful in that respect except I had thought it would've had the same effect as physically holding the key on the keyboard)

    As for this new suggestion you have here I am taking a look at it to see if it's any better for my situation, I thank you greatly for your help in trying to give an answer to my problem that may work better than other things that have been come up with so far.

    If this fails I fear that it will then be beyond my capabilities to actually create a program that will do this the way that I have intended.

    As for more info on the solution you gave before I had already been having it inside a background worker but I didn't create multiple background workers & or also use the main thread, I have a multi core pc although no cpu cores are being pegged at 25%(1 cores total speed of my quad core cpu), would it make a difference even when the cores aren't being pegged??  I will try & speed it up just for testing by using multiple background workers & or using the main thread as well just to see the results but i'm not sure that would help even.

    As I said i'm looking at your new suggestion but failing that it would be beyond my abilitys to make it work as intended, would just mark your answers as helpful & get on with it the way i use already.

    Tuesday, September 6, 2011 6:40 PM
  • Hi Michael,

    Thank you for posting on MSDN Forum.

    I have test Reed's code, it works for me. And I didn't find a better solution about this issue until now. It would be nice if you can check it again to find some useful things.

    Have a fine day.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Mike Feng Thursday, September 8, 2011 12:15 PM
    Thursday, September 8, 2011 12:13 PM