Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The error "The calling thread cannot access this object because a different thread owns it." is quite standard for WinForms and WPF controls. </p> <p>In WPF and WinForms windows are rendered on the screen using one specific thread, usually called UI thread. Every update/change action regarding controls should take place on that thread to have success. </p> <p>Usual way to go with WinForms is to create a special delegate and call Control.Invoke as shown in this <a href="http://msdn.microsoft.com/en-us/library/zyzhdc6b%28v=vs.80%29.aspx">link</a>. </p> <p>As of WPF, same effect is achieved with the use of a <a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.invoke.aspx">Dispatcher</a>. Your code should look like this:</p> <pre><code>this.Dispatcher.Invoke( () =&gt; svImages.ScrollToHorizontalOffset(svImages.HorizontalOffset - 0.1)); </code></pre> <p><strong>UPDATE:</strong></p> <p>I've got the following code to work in VB.NET:</p> <pre><code>Private Delegate Sub ScrollDelegate(ByVal offset As Double) Private Sub ScrollLeft(ByVal offset As Double) svImages.ScrollToHorizontalOffset(svImages.HorizontalOffset + offset) End Sub // ... calling from background thread Dim slt As ScrollDelegate slt = New ScrollDelegate(AddressOf ScrollLeft) Me.Dispatcher.Invoke(slt) </code></pre> <p><strong>Update 2</strong></p> <p>Code changed as to the question.</p> <pre><code>Dim ScrollLeft As Boolean = True Dim atimer As New System.Timers.Timer() Dim scrollMethod As ScrollDelegate Private Delegate Sub ScrollDelegate(ByVal offset As Double) // ... Me.InitializeComponent() slt = New ScrollDelegate(AddressOf DoScroll) // ... Private Sub timer_Tick(sender As Object, e As EventArgs) If ScrollLeft Then Me.Dispatcher.Invoke(slt, -1) Else Me.Dispatcher.Invoke(slt, 1) End If End Sub // ... Private Sub DoScroll(ByVal offset As Double) svImages.ScrollToHorizontalOffset(svImages.HorizontalOffset + offset) End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload