|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Threading - Object reference not set to an instance of an objectto provide a little background on this app...I am calling this from an aspx page. Feeding in the params and basically hoping to go out to the servers specified in the xml files, run the command that I passed in and return the output from the server. I was able to make this work with a single thread and a single server. Now...it is time to beef it up a bit...and multi-thread it. I haven't messed with threading much in the past...and I am sure that someone will respond with "learn to crawl before you learn to run." If life were that simple... I continue to get the Object reference not set error when I call this dll. It compiles fine...but, something is obviously not initializing properly...and I am just missing it. I wrote a quick test function and put it in the sshSearch Class and it worked fine...shich means that the SearchNet function is NOT working fine. I would really appreciate ANY help that ANYONE can provide. I have been researching this for about 2 weeks...including the purchase of a new book (dang things are expensive) and just about every group that I can find. Again...thanks!!! Jay Imports System Imports System.IO Imports System.Web Imports System.Xml Imports System.Text Imports System.Data Imports System.Threading Imports System.Diagnostics Imports Microsoft.VisualBasic Namespace SearchThis Public Class sshSearch Public allResults As String Public strNow As String Public Function SearchNet( strSearch As String,intLogLevel As Integer ) Dim dtmNow As DateTime dtmNow = DateTime.Now() strNow = dtmNow.ToString("MMddyyyyhhmmss") Dim usrname As String usrname = "username" Dim pw As String pw = "password" Dim cfg As New XmlDataDocument Dim strServerGroup As String strServerGroup = "cbaa" If strServerGroup = "cbaa" Then cfg.Load( "d:\inetpub\wwwroot\HAT\bin\searchnet" & strServerGroup & ".config" ) End If Dim ndList As XmlNodeList ndList = cfg.SelectNodes("//ServerMenuItemIpAddress") Dim nd As XmlNode Dim i As Integer Dim s(32) As ThreadData Dim t As Thread i = 0 For Each nd in ndList Dim serverIpAddress As String serverIpAddress = nd.InnerText Dim strPlinkArguments As String strPlinkArguments = "-ssh -l " & usrname & " -pw " & pw & " " & usrname & "@" & serverIpAddress & " -batch " & strSearch s(i) = New ThreadData s(i).strPlinkArguments = strPlinkArguments t = New Thread(AddressOf s(i).DoTheWork) t.Start() i = i + 1 Next Dim j As Integer Dim allDone as Boolean Do Until allDone allDone = True For j = 0 to i - 1 allDone = allDone And s(i).Done Next Loop For j = 0 to i - 1 allResults = allResults + s(j).GetResults Next If intLogLevel = 1 Then Dim sw As New StreamWriter("D:\inetpub\wwwroot\HAT\searchnetlogs\searchnet" & strNow & ".txt") sw.write(allResults) sw.Close() End If Return allResults End Function End Class Public Class ThreadData Public strPlinkArguments As String Public Done As Boolean Public searchText As String Public Sub DoTheWork() Dim sr As StreamReader Dim sb As New StringBuilder("") Dim input As Integer Dim proc As Process = New Process() proc.StartInfo.FileName = "d:\inetpub\wwwroot\HAT\bin\plink.exe" proc.StartInfo.Arguments = strPlinkArguments proc.StartInfo.UseShellExecute = False proc.StartInfo.RedirectStandardOutput = True proc.Start() sr = proc.StandardOutput input = sr.Read Do Until input = -1 sb.Append(ChrW(input)) input = sr.Read Loop searchText = sb.ToString sr.Close() proc.Close() Done = True End Sub Public Function GetResults() Return searchText End Function End Class End Namespace jay,
Do you really want to make from a ASPNet application a multithreading one. Don't forget that the ASPNET application is the middle tier for all your users being active with that. If you don't screw up your server with adding extra threading, you are probably doing it yourself. Just my thought, Cor The thought has crossed my mind...more from a coding perspective (i.e.
I have been unable to solve this coding issue) than from a performance perspective. There are times when this application will need to connect to 16-20 servers, run a command and return the results. The server that this is running on is a multiple CPU server wch does allow for a performance gain when it comes to threading. I appreciate the heads up...but, I also know that in the end, the amount of connections needed to be made will require some form of threading to be efficient. J |
|||||||||||||||||||||||