Hack Forums
[.NET] How do i start thread with option strict? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] How do i start thread with option strict? (/showthread.php?tid=2448502)



How do i start thread with option strict? - Moen - Apr 29, 2012

I am trying to code with "option strict" = on
this code is working with "option strict" = off

So what did i miss to make it possible for option strict?
[Image: 5XJ7c.png]

Error message:
Code
Error    1    Overload resolution failed because no accessible 'New' can be called with these arguments:
    
    'Public Sub New(start As System.Threading.ParameterizedThreadStart)': Option Strict On does not allow narrowing in implicit type conversions between method 'Private Sub mysub(ms As Integer)' and delegate 'Delegate Sub ParameterizedThreadStart(obj As Object)'.
    
    'Public Sub New(start As System.Threading.ThreadStart)': Method 'Private Sub mysub(ms As Integer)' does not have a signature compatible with delegate 'Delegate Sub ThreadStart()'.    C:\Users\***\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb    5    13    WindowsApplication1



* - hio2hio - Apr 29, 2012

Try this code:
Dim th as new threading.thread(new Parameterizeredthreadstart(addressof mysub))


* - Perplexity - Apr 29, 2012

Code
Dim th As New Threading.Thread(New Threading.ThreadStart(Sub() mysub(delay)))
th.Start()



* - ident - Apr 29, 2012

You are parsing data to a entry thread method.

Code
Dim delay As Integer = 5000
Dim th As New Threading.Thread(DirectCast(Sub() MySub(delay), Threading.ThreadStart))
With th
    .IsBackground = True
    .Start()
End With



* - Moen - Apr 29, 2012

(Apr 29, 2012 03:12 PM)Perplexity Wrote:  
Code
Dim th As New Threading.Thread(New Threading.ThreadStart(Sub() mysub(delay)))
th.Start()

Thanks for the replies
Will be using Perplexity's code