Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot use Window control simultaneously in two threads
    primarykey
    data
    text
    <p>From the Page_load event of Window1 I'm calling a function of a public class and passing parameter as the same Window1. After the function is called, a thread is started. The thread is called on Page_Loaded event of Window1. The code is like this:</p> <pre><code>Private Sub StartScreen_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded Try TmHeartbeat.Stop() TmHeartbeat.Interval = 600000 TmHeartbeat.Start() ResetVariables() FormLoadSetting(Me) SetButtonProperty(btnEnglish, "\Images\ButtonBgBig.png", GetFormLabel("Start Screen", "Common", "Button English")) SetButtonProperty(btnSpanish, "\Images\ButtonBgBig.png", GetFormLabel("Start Screen", "Common", "Button Spanish")) SetDisplayTimer(DGT, False, Me, 1800000) MediaElement1.Source = New Uri(GetPath("Images\EnglishVideo\" &amp; GetFormLabel("Start Screen", "Common", "Video"))) If GetFormLabel("Start Screen", "Common", "Audio") &lt;&gt; "" Then PlayAudio(APlay, GetFormLabel("Start Screen", "Common", "Audio")) End If Dim AudioPlay As New System.Media.SoundPlayer Dim sc As New Screenshot sc.TakeScreenshot(Me) Catch ex As Exception AliLogFileEntry(TransactionType.ErrorOnForm, "Error In Function: StartScreen_Loaded: " &amp; Me.Title &amp; ", ErrorMessage: " &amp; ex.Message) End Try End Sub </code></pre> <p>The function <code>TakeScreenshot(Me)</code> which is in class <code>Screenshot</code> is called. Along with the Screenshot class, I also have another class named <code>GetScreenshot</code> and a function <code>TakeScreenshot1</code>. The code for the class file is like this:</p> <pre><code>Imports System.IO Imports System.Threading Public Class Screenshot Public Sub TakeScreenshot(ByVal formname As Window) Dim GT As New GetScreenshot GT.source = formname Dim newThread As New Thread(AddressOf GT.TakeScreenshot1) newThread.Start() End Sub End Class Public Class GetScreenshot Public source As Window Public Function TakeScreenshot1() Thread.Sleep(2000) If OG.GetValue("TakeScreenshot") &lt;&gt; "0" Then Try AliLogFileEntry(TransactionType.System, "In Function: TakeScreenshot") Dim scale As Double = OG.GetValue("Screenshot_Scale") / 100 AliLogFileEntry(TransactionType.System, "In Function: GetJpgImage") Dim renderHeight As Double = source.RenderSize.Height * scale Dim renderWidth As Double = source.RenderSize.Width * scale Dim renderTarget As New RenderTargetBitmap(CInt(Math.Truncate(renderWidth)), CInt(Math.Truncate(renderHeight)), 96, 96, PixelFormats.Pbgra32) Dim sourceBrush As New VisualBrush(source) Dim drawingVisual As New DrawingVisual() Dim drawingContext As DrawingContext = drawingVisual.RenderOpen() Using drawingContext drawingContext.PushTransform(New ScaleTransform(scale, scale)) drawingContext.DrawRectangle(sourceBrush, Nothing, New Rect(New Point(0, 0), New Point(source.RenderSize.Width, source.RenderSize.Height))) End Using renderTarget.Render(drawingVisual) Dim jpgEncoder As New JpegBitmapEncoder() jpgEncoder.QualityLevel = 100 jpgEncoder.Frames.Add(BitmapFrame.Create(renderTarget)) Dim _imageArray As [Byte]() Using outputStream As New MemoryStream() jpgEncoder.Save(outputStream) _imageArray = outputStream.ToArray() End Using Dim screenshot As Byte() = _imageArray Dim dir As DirectoryInfo = New DirectoryInfo("Screenshots") If Not dir.Exists Then dir = Directory.CreateDirectory(dir.FullName) Dim path As String = AppDomain.CurrentDomain.BaseDirectory Dim fileStream As New IO.FileStream("Screenshots\" &amp; source.Title &amp; ".jpg", FileMode.Create, FileAccess.ReadWrite) Dim binaryWriter As New IO.BinaryWriter(fileStream) binaryWriter.Write(screenshot) binaryWriter.Close() Catch ex As Exception AliLogFileEntry(TransactionType.ErrorOnForm, "Error In Function: TakeScreenshot , ErrorMessage: " &amp; ex.Message) End Try End If End Function End Class </code></pre> <p>When I debug this file, I get this error: <img src="https://i.stack.imgur.com/QtXgg.jpg" alt="enter image description here"></p> <p>And the error is generated on line </p> <pre><code>Dim sourceBrush As New VisualBrush(source) </code></pre> <p>Pleas help</p>
    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.
 

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