473,379 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Threading - Object reference not set to an instance of an object

jay
Believe it or not...I am new to this side of development. I will try
to 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

Feb 28 '06 #1
2 1774
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
Feb 28 '06 #2
jay
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

Feb 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Doug Thews | last post by:
I'm writing some sample threading code, and have already got many examples working that look a lot similar to the ones mentioned here. What I'm seeing is that most people put their method that...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
3
by: Asad | last post by:
Hi, I am trying to write some threading code to my application. The reason I've been tempted to do this is because, I am doing some FTP uploads, and sometimes during the put method, the...
8
by: MattB | last post by:
Hello I am starting a new thread in a button click event. This thread calls an method which sends emails, I don't want the page to wait for the emails to finish going out as it slows the user...
9
by: AdrianJMartin | last post by:
Hi all, I have a need for a STA thread from asp.net. I can create the thread and it runs fine. But when it is finished, the thread still 'hangs' arround. Visible only to the debugger..... I get...
2
by: 1944USA | last post by:
I am re-architecting a C# application written as a multithreaded Windows Service and trying to squeeze every bit of performance out of it. 1) Does the thread that an object is instantiated on...
14
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I just started learning Threading in C#. I read lot of articles and what I am trying to accomplish here is that I have an array of string and I want to pass the member of that...
9
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
6
by: George Sakkis | last post by:
I'm baffled with a situation that involves: 1) an instance of some class that defines __del__, 2) a thread which is created, started and referenced by that instance, and 3) a weakref proxy to the...
13
by: Alexander Gnauck | last post by:
Hello, while using async sockets I ran into a strange problem which occurs only on some machines. I wrote a small demo application which can be used to reproduce the problem. You can download it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.