I'm having a problem with threading (permissions?) in a VB.net
Windows application (background service). I'm trying to write an
application that processes files, launching a new thread for each file
that is dropped into a certain folder. Now, the application works like
a charm on my Win2000 machine, but when I moved it to the Win2000
server, where it will eventually need to run, it fails. One of the
processes that is run on the file is a process to decrypt the file, and
this is the only process that won't work on the server. Since there
is no debugger on the server, I just stripped down the application, so
I could find where the problem is. It turns out that the decryption
process will work on the server if I call the method directly. But, if
I instantiate a child thread to handle the file, and that thread calls
the decryption process, then the application fails. A funny thing is
that if I put a Msgbox in the middle of the decryption process and
click the OK button when it pops up, then the process works fine, even
with the instantiation. Too bad I don't want the Msgbox.
Anyway, here's an edited version of the stripped-down code:
Public Module DecryptTestParent
Public Sub Main()
'''''' Version 1: Direct Call - This works fine ''''''
'Dim dtCh As New DecryptTestChild()
'dtCh.DoDecrypt()
''''''''''''''''''''''''''''''*''''''''''''''''''' '''''
'''' Version 2: Instantiation - This doesn't work ''''
Dim dtCh As New DecryptTestChild()
Dim pThread As New System.Threading.Thread( _
New System.Threading.ThreadStart(A*ddressOf
dtCh.DoDecrypt))
pThread.Start()
' Just to make sure parent doesn't somehow strand child
While pThread.IsAlive : End While
''''''''''''''''''''''''''''''*''''''''''''''''''' '''''
End Sub
End Module
Public Class DecryptTestChild
Public Sub DoDecrypt()
Dim ReturnObject As Object = fctDecryption( _
"..\..\Files_Repository\Encryp*tedFile.sur")
If Not IsError(ReturnObject) Then
MsgBox(ReturnObject.ToString)
Else : MsgBox(ReturnObject.Message.To*String())
End If
End Sub
Public Function fctDecryption(ByVal FileName As String) As Object
' This method has been editted for privacy and simplicity.
' Just know that it eventually calls a 3rd-party decryption
' module in order to decrypt the file.
Return DecryptedStringOrException
End Function
End Class
Now it's likely that the 3rd-party decryption class creates,
accesses, or deletes temporary files and accesses private information
for somewhere, and it's failing on the server because it doesn't
have permission to do so. Is that right? Is there some issue with
child threads not having the same permissions as the parent? Is there
something that I can do about that? I tried setting the parent
thread's CurrentPrincipal to the child's CurrentPrincipal, but it
didn't help. Maybe I wasn't doing it properly, though.
Any help?
Thanks.