|
Sure. The VB.NET class just has to be it's own project. Then, in your C# project, you can set a project (preferrably) reference to the VB.NET project and include the class just like any other pre-written namespace and class in the .NET Framework.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hey everyone...
i've probably missed something very important, and just don't know it.
the reason: i'm trying to populate 2 treeviews from 2 separate threads with separate data in each, both trees are pretty slow to load so i need the threads, else i lock up the ui for about 10sec. I also have to refresh the trees throughout the progress so i've had to build the threads the way i have so i can access it later.
the problem: if i try to invoke both threads in the same form_load block i end up with 2 trees with the same data. if i invoke them separately (comment one or the other out) i have proven that the code works properly for both, so it leads me to believe that i've either done something terribly wrong or i just can't do what i'm trying to do........
any ideas?
here is the code:
Thread PcTree, pclist,EmpTree,emplist;
MethodInvoker CallCompList, CallEmpList;
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
switch (tabControl1.SelectedIndex)
{
case 0:
initializePcTree();
break;
case 4:
initializeEmpTree();
break;
}
}
private void initializePcTree()
{
PcTree = new Thread(new ThreadStart(PopComputerList));
PcTree.IsBackground = true;
PcTree.Name = "PcTree";
PcTree.Start();
}
private void initializeEmpTree()
{
EmpTree = new Thread(new ThreadStart(PopEmpList));
EmpTree.IsBackground = true;
EmpTree.Name = "EmpTree";
EmpTree.Start();
}
private void PopComputerList()
{
CallCompList = new MethodInvoker(CompList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallCompList);
}
private void PopEmpList()
{
CallEmpList = new MethodInvoker(EmpList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallEmpList);
}
private void newCompList()
{
CompList();
}
private void newEmpList()
{
EmpList();
}
private void CompList()
{
statusBarPanel1.Text = "Please Wait While We Update the List";
PCmonitorTree.Nodes.Clear();
ParentNode = new TreeNode("TopNode");
PCmonitorTree.Nodes.Add(ParentNode);
foreach(SearchResult sr in ds.FindAll())
{
TreeNode PCnode = new TreeNode();
PCnode.Text = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
ParentNode.Nodes.Add(PCnode);
TreeNode PCnode1 = new TreeNode();
PCnode1.Text = "PC - " +sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
PCnode1.Tag = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
PCnode.Nodes.Add(PCnode1);
PCmonitorTree.Sorted = true;
}
PCmonitorTree.ExpandAll();
t = ParentNode;
PCmonitorTree.SelectedNode = t;
statusBarPanel1.Text = "Ready";
}
private void EmpList()
{
statusBarPanel1.Text = "Please Wait While We Update the List";
empTree.Nodes.Clear();
TreeNode ParentNode = new TreeNode("TopNode");
empTree.Nodes.Add(ParentNode);
foreach(SearchResult sr in ds.FindAll())
{
DirectoryEntry DE = sr.GetDirectoryEntry();
TreeNode empnode = new TreeNode();
empnode.Text = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
empnode.Tag = sr.GetDirectoryEntry().Name.Split("=".ToCharArray())[1].ToString();
ParentNode.Nodes.Add(empnode);
empTree.ExpandAll();
empTree.Sorted = true;
}
t=ParentNode;
empTree.SelectedNode = t;
statusBarPanel1.Text = "Ready";
}
string Beautiful;
Beautiful = "ignorant";
label1.Text = "The world is full of " + Beautiful +" people.";
Why is common sense such an un-common comodity?
|
|
|
|
|
You cannot call methods on Controls created on another thread. T do this, you have to use the Invoke methods of the Controls.
See this: http://blogs.wwwcoder.com/amachin/archive/2004/12/15/1146.aspx[^]
EDIT: Sorry, misread your article. You are using BeginInvoke, this should work. Anyway, you probably should read the article linked above, it may solve your issue.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
-- modified at 12:06 Friday 20th January, 2006
|
|
|
|
|
private void PopComputerList()
{
CallCompList = new MethodInvoker(CompList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallCompList);
}
private void PopEmpList()
{
CallEmpList = new MethodInvoker(EmpList);
de = new DirectoryEntry("LDAP://~.com");
ds = new DirectorySearcher(de);
ds.Filter = ("(~)");
this.BeginInvoke(CallEmpList);
}
Look what you're doing here with the de and ds variables. You're using a class scoped de and ds variables. DON'T! Each thread should create and use it's own set of Directory objects scoped within the methods themselves.
What's happening is that when you launch your first thread, it sets up the de and ds variables to perform a search. While that setup and search is taking place, you launch another thread that, low and behold, reassigns new DirectorySearcher and DirectoryEntry objects to the very same de and ds variables you just setup in your previous thread. Global variables - bad idea...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 12:26 Friday 20th January, 2006
|
|
|
|
|
Good point Dave,
I think i picked up that bad habit from those redim-ing vb guys i work with
problem fixed!
string Beautiful;
Beautiful = "ignorant";
label1.Text = "The world is full of " + Beautiful +" people.";
Why is common sense such an un-common comodity?
|
|
|
|
|
I'm calling a method that can throw one of several exceptions:
byte[] ReadFile(string filePath)
{
return File.ReadAllBytes(filePath);
}
When calling this method, do you guys usually catch every possible exception, or just cover it with a single catch block? For example, do you do this:
string errorMessage = null;
try
{
return File.ReadAllBytes(filePath);
}
catch (ArgumentException argumentError)
{
errorMessage = argumentError.Message;
}
catch (ArgumentNullException nullArgumentError)
{
errorMessage = nullArgumentError.Message;
}
catch (PathTooLongException pathError)
{
errorMessage = pathError.Message;
}
catch (DirectoryNotFoundException directoryNotFoundError)
{
errorMessage = directoryNotFoundError.Message;
}
catch (IOException ioError)
{
errorMessage = ioError.Message;
}
catch (UnauthorizedAccessException unauthorizedError)
{
errorMessage = unauthorizedError.Message;
}
catch (FileNotFoundException fileNotFoundError)
{
errorMessage = fileNotFoundError.Message;
}
catch (NotSupportedException notSupportedError)
{
errorMessage = notSupportedError;
}
catch (System.Security.SecurityException securityError)
{
errorMessage = securityError;
}
if(errorMessage != null)
{
MessageBox.Show(errorMessage, ...);
}
Or do you catch it all in a single System.Exception catch block?
try
{
File.ReadAllBytes(filePath);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, ...);
}
Obviously the latter is easier to read and write, but the former is more precise and won't eat up things like system errors (OutOfMemoryException, OverflowException, etc.). Which do you guys suggest?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango
|
|
|
|
|
It depends. For example, when reading a file I'll normally check it exists first, so I a PathTooLongException, DirectoryNotFoundException and FileNotFound are really things I should not be getting, so they'd be covered in a catch all (if at all at that point in the code). Specific things that I can't check for in advance would be in specific blocks.
On the whole I find that exceptions propogate up a couple of method calls in the stack before I actually handle them because often at the point the exception occurs I am not able to handle it so I allow it to propogate up until I can do something about it.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Or in case of IO operation it would be better to do:
catch (IOException ex)
{
.. io error occured. PathTooLongException and all other IO related inherit from IOException
}
catch (Exception ex)
{
.. all other unexpected errors
}
|
|
|
|
|
My example was simplified; my real code has the error propagating up a ways until it gets to the UI as well.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango
|
|
|
|
|
I use selected row data of dataGrid to load data into textboxes
When I select the first row of the dataGrid no data is loaded into the textboxes
But when I select any other row, it’s data is loaded to the textboxes, then the first row can be loaed too...!!!!?
If any one knows the reason why the first row don't load until i select any other row at first, I’ll be grateful
|
|
|
|
|
try posting your code so we can determine what is going on.
|
|
|
|
|
How are you loading the data into the textboxes? If you're handling the rowEnter event, I don't believe its raised on the form/page load. Try going to any other row, then back to the first and see if it loads. If that's so, you may have to either just manually enter the data into the columns the first time, or use a different event.
As another option, look into databinding. There are a couple WONDERFUL articles on it here at codeproject that you can search for.
|
|
|
|
|
|
Hi,
DataTable.Clear() really clears all the rows from the memory r just changes the status of the rows?
If it does not clear which is the best method to use to clear the DataTable rows from the memory.
Thanks and Regards,
Subbu
|
|
|
|
|
I want to show a Power Point presentation file from my C# application. Does anyone know how to do that, without having the program Power Point installed on the locale machine? I think of a COM-component maybe?
--
Michael Bested
|
|
|
|
|
Hello to all,
I have to generate stream of different media format with different protocols(RTP,MMS,..).
Now i have one dll for that.
But i hae no idea to operat it.
so, any body who work on this can help me plz.
Thank you
|
|
|
|
|
Divyang Mithaiwala wrote: Now i have one dll for that.
But i hae no idea to operat it.
We know less than you do. You, at least, have the DLL and can put it thought something like Reflector to see what it is doing.
However, the question I have is: Why don't you read the documentation that came with this dll?
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
I read that document but they not suggest that how to start. & Sample code they give are not run perfectly with my system. In document they just give the detail if all class & methods of that.
|
|
|
|
|
If you don't want to spend hours trying to "make it work", then your next best source of information is the people who wrote the library.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello,
Plz Help
I have datagrid bound to a dataset
My datagrid shows a column "UID"
having some incremental values, I am having a value say 5,
When I am writing
dataGrid1.Select(5)
it is giving me an error that index array out of bound
I am filling the dataset using Fill method having only one table
hi it is rudara
|
|
|
|
|
Hello,
Plz Help
I have datagrid bound to a dataset
My datagrid shows a column "UID"
having some incremental values, I am having a value say 5,
When I am writing
dataGrid1.Select(5)
it is giving me an error that index array out of bound
I am filling the dataset using Fill method having only one table
Thanks & Regards
hi it is rudra
|
|
|
|
|
hi,
i'm currently working on a project following the concept of Float's Mobile Agent - where you can control a sony ericsson phone (t610) from a PC via Bluetooth. i was hoping if anyone can help me code in C# on how to do the same on either a Nokia 6600 or P800 (both Symbian-operated). i'm thinking of using Java as a middleware too. i would really appreciate your help ^_^
|
|
|
|
|
Hello guys,
I like to retrieve MAC addresses arround my network without the use of SendARP. The network is huge and contains a lot of subnets. Since ARP doesn't go to other subnets I need to find another method.
Programs like nbtstat -a <hostname> and getmac /s <hostname> do what they have to do. Altought I like to have it my program.
Any idea's?
Another option is to use getmac /s <hostname> /fo csv and get the output. How do I manage that?
Small upate:
I don't want to use WMI to retrieve the MAC address.
Thanks in advance.
-- modified at 7:52 Friday 20th January, 2006
|
|
|
|
|
Hello,
I found a sort of solution. I hope to help other people out with this...
<br />
string sComputerName = "";
try<br />
{<br />
Process p = new Process();<br />
string cmd = "";<br />
cmd = System.Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\cmd.exe";<br />
p.StartInfo.FileName = cmd;<br />
p.StartInfo.Arguments = "/C nbtstat -a " + sComputerName + "";<br />
p.StartInfo.RedirectStandardOutput = true;<br />
p.StartInfo.UseShellExecute = false;<br />
p.StartInfo.CreateNoWindow = true;<br />
p.Start();<br />
p.WaitForExit(1000);<br />
string output = p.StandardOutput.ReadToEnd();<br />
<br />
if (CharCount(output, "MAC Address = ") != 0)
{<br />
int iPos = output.IndexOf("MAC Address = ");<br />
sMacAddress = Mid(output, iPos + 14, 17);<br />
}<br />
}<br />
catch (Exception) {}<br />
<br />
public static string Mid(string strParam, int startIndex, int length)<br />
{<br />
string tmpstr = strParam.Substring(startIndex, length);<br />
return tmpstr;<br />
}<br />
<br />
public static int CharCount(string strSource, string strToCount)<br />
{<br />
int iCount = 0;<br />
int iPos = strSource.IndexOf(strToCount);<br />
while (iPos != -1)<br />
{<br />
iCount++;<br />
strSource = strSource.Substring(iPos + 1);<br />
iPos = strSource.IndexOf(strToCount);<br />
}<br />
return iCount;<br />
}
|
|
|
|
|
I am interested in a way, using the .NET Framework classes, to obtain a MAC address based on an IP number. Knowing an IP number, I need to know to extrapolate the MAC address. How can this be done with the .NET Framework and C#? I know that the MAC is not in the Request object, I need some guidance on getting the MAC *after* I have used the Request object to get the IP number. I have found some about using the "System.Management" Namespace already.
I'm assuming the machine running the function and the remote machine we are trying to obtain the physical address of are on the same network segment and are not separated by a firewall.
Any thoughts about a solution to the problem?
|
|
|
|