|
Actually I do have that check in my code already:
if(myServers!=null)
{
foreach(Server s in myServers)
{
if(s.Name!=null)
{
this.lstViewNetwork.Items.Add(s.Name.Clone().ToString(), 0);
}
}
}
This is the most common error and the one you mentioned:
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll Additional information: Object reference not set to an instance of an object.
When hitting break it goes to assembly... not a line of code as you normally get with null reference... when it does have the mscrolib error it get the green arrow break (don't know what the differance between that and the yellow is) but that is in the '}' underneath application.run(form)
Like I said, I'll send you the code if you have the time to look it.
Thanks again
Brian
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
Here is the code for the struct I use in the example:
<br />
public struct Server<br />
{<br />
private string n, c;<br />
public string Name<br />
{<br />
get { return n; }<br />
set { n = value; }<br />
}<br />
public string Comment<br />
{<br />
get { return c; }<br />
set { c = value; }<br />
}<br />
public Server(string name, string comment)<br />
{<br />
n = name;<br />
c = comment;<br />
}<br />
}<br />
Here is the code for the GetServers function, this function is part of the public class Network(), the dotNet_OpenEnum, dotNet_CloseEnum, and dotNet_EnumResources are static functions in a wrapper class for each of the API network functions... I did this versus calling the external function directly, the Flags class is simply const int's for various flags used when using the API network functions:
<br />
public static Server[] GetServers(string domainName)<br />
{<br />
int ret;<br />
IntPtr ptrBuffer;<br />
IntPtr ptrHandle = new IntPtr();<br />
int BufferSize = short.MaxValue;<br />
int NumberRequested = -1;<br />
NETRESOURCE objNR = new NETRESOURCE();<br />
objNR.lpRemoteName = domainName;<br />
object obj = (object) objNR;<br />
if(obj==null)<br />
{<br />
return null;<br />
}<br />
ret = dotNet_WNetOpenEnum.Execute(Flags.RESOURCE_GLOBALNET, Flags.RESOURCETYPE_ANY, Flags.RESOURCEUSAGE_ALL, obj, out ptrHandle);<br />
if(ret!=0)<br />
{<br />
if(ptrHandle!=IntPtr.Zero)
{<br />
ret = dotNet_WNetCloseEnum.Execute(ptrHandle);<br />
}<br />
return null;<br />
}<br />
ret = 234;<br />
ptrBuffer = Marshal.AllocHGlobal(0);<br />
while(ret==234 || ret==487)
{<br />
NumberRequested=-1;<br />
ret = dotNet_WNetEnumResource.Execute(ptrHandle, ref NumberRequested, ptrBuffer, ref BufferSize);<br />
if(ret!=0)<br />
{<br />
Marshal.FreeHGlobal(ptrBuffer);<br />
BufferSize*=2;
ptrBuffer = Marshal.AllocHGlobal(BufferSize);<br />
}<br />
}<br />
if((ret!=0) || (NumberRequested < 1))<br />
{<br />
if(ptrBuffer!=IntPtr.Zero)<br />
Marshal.FreeHGlobal(ptrBuffer);
if(ptrHandle!=IntPtr.Zero)
{<br />
ret = dotNet_WNetCloseEnum.Execute(ptrHandle);<br />
}<br />
return null;<br />
} <br />
Server [] servers = new Server[NumberRequested];<br />
int PtrMovement;<br />
NETRESOURCE nr;<br />
PtrMovement = ptrBuffer.ToInt32();<br />
for(int n=0;n<NumberRequested;n++)<br />
{ <br />
nr = (NETRESOURCE) Marshal.PtrToStructure(new IntPtr(PtrMovement), typeof(NETRESOURCE));<br />
servers[n] = new Server(nr.lpRemoteName, nr.lpComment);<br />
PtrMovement += Marshal.SizeOf(typeof(NETRESOURCE));<br />
}<br />
Marshal.FreeHGlobal(ptrBuffer);
ret = dotNet_WNetCloseEnum.Execute(ptrHandle);<br />
return servers;<br />
}<br />
Thanks for any help!
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
Heath -
So I took out all of the additions we made and put it back to square one and at the bottom of the function I added GC.Collect():
<br />
string domain="Domain1";<br />
this.lstViewNetwork.Items.Clear();<br />
Server [] myServers;<br />
myServers = Network.GetServers(domain);<br />
this.lstViewNetwork.BeginUpdate();<br />
if(myServers!=null)<br />
{<br />
foreach(Server s in myServers)<br />
{<br />
if(s.Name!=null)<br />
{<br />
this.lstViewNetwork.Items.Add(s.Name, 0);<br />
}<br />
}<br />
}<br />
count++;<br />
this.lstViewNetwork.EndUpdate();<br />
this.lblRefresh.Text = count.ToString();<br />
GC.Collect();<br />
}<br />
Now I know longer get errors, and everything is working perfectly (... some weird things still happen, when the screen saver started the form became the screen saver... weird... and once I got an error on closing the form, but after several attempts to get it to happen I haven't been able to, and something similiar when losing and regain focus to the form, it can now go throughs several thousand iterations before either of these errors happen whereas before we couldn't go more than 150. I'm not sure why GC.Collect() has made the error go away, but I know a 'fix to the problem' and 'fixing the problem' are two seperate worlds, and I was hoping maybe with this information and the other information I've given since your last reply will set some bells off in your head... any ideas?
Thanks again for all your help with this.
Brian
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
Are you executing this method in a separate thread? If so, you must make all UI updates on the main UI thread. See Control.InvokeRequired and Control.Invoke for more information. Basically, you invoke your method (using a delegate with a matching signature to this.lstViewNetwork.Items.Add(s.Name, 0) and call Control.Invoke on that. This can cause similar problems to what you're seeing if you do add items on a separate thread. This is just the way Windows works (and most other window managers that I'm familiar with).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath,
Thanks again for all your help, I solved it. I am flawless now... it wasn't what we were expecting... it was something really stupid - something we looked over. I was over-allocating memory in my function - apparently when you send to much memory to WNetEnumResources it fills the rest of the memory with items, then when calling it again your not getting the new memory, but the remainder of the old, and the new memory for the new objects is pushed up the stack - I know that's a terrible explination but it appears that is what was happening. Now that I'm allocating it correctly I have no problems whatsoever in any context... console or form and I have reloaded my ListView control every second for over an hour with simple .Add(s.Name) and not so much as a flicker.
I wanted to thank you once again for you help along the way. I learned a lot on this one... if you ever want a copy, please email me.
Brian
If you ever meet somebody who says they know it all, they are obviously ignorant and probably write terrible code.
|
|
|
|
|
We have an issue with using the IE ActiveX control where about 1 in 20 users are expriencing total system lockup when our application loads.
The application is being deployed with the following files:
AxInterop.SHDocVw.dll
Interop.SHDocVw.dll
partial.mshtml.dll
The partial.mshtml.dll file comes from SharpReader[^], and by all accounts fixed their deployment problems, which are similar to our own.
I have extensive trace output in the app, and can verify that the point of lockup is when the web browser control is instantiated. Please note that I am navigating to about:blank in the constructor to ensure the control has a handle.
Has anyone else ran into similar problems deploying a C# app with the IE control? if so, any ideas?
|
|
|
|
|
I doubt this would cause a lockup, but what versions of Internet Explorer are the 1 in 20 users using? If the partial.mshtml.dll was created with a newer version that those few users don't have, and you're trying to use those newer interfaces that don't exist in the MSHTML DOM, this would most likely cause a problem. Your installer should make sure they have the proper version (or higher) of IE.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I am working closely with one affected user on the issue.
He is using Win98SE, with IE 6 SP1. I have added a bunch of trace output to the app, and the total system lockup is happening right after the ActiveX is instantiated, when the control would be receiving a handle I guess.
I've tried compiling the app for both 1.0 and 1.1 framework versions, and I've referenced & distributed the entire Microsoft.mshtml.dll assembly.
As for the control itself, I am only calling the Navigate method, and catching the OnNavigateComplete2 event - nothing else.
Note that I have 26 other people using the app with Win98 + IE 5-6 without problem, but this one fellow is experiencing lockups on both of his Win98 SE systems. Outside of him, who knows how many people have dismissed the app as inoperable and simply not advised me!
|
|
|
|
|
Man, I don't know. How much memory does this person have in his machines? I mean, the .NET Framework would throw an exception and exhausting the memory wouldn't lock up the system, but it might appear that way. I doubt this is the problem, though.
Have you checked the MS KB? Besides that, all I can think to tell you is to post a message to an appropriate MS newsgroup (msnews.microsoft.com), but I doubt that'll help since replies to more advanced or "odd" problems like this almost never get answered.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
How much memory does this person have in his machines?
One has 64MB, the other 128MB, however my low-end test machine (that runs the app fine) has just 56MB usable RAM (8 MB is taken up by the video card).
Heath Stewart wrote:
Have you checked the MS KB?
Yes. The only possibly related article I could find was a COM import bug in fx 1.0 that was fixed in 1.0 SP1. However, compiling the app for fx 1.1 should have worked around this issue if it was the problem.
Heath Stewart wrote:
Besides that, all I can think to tell you is to post a message to an appropriate MS newsgroup
Have now posted the problem to microsoft.public.dotnet.framework, but as you noted and I've personally experienced, difficult questions seem to get lost in the ether...
Thanks for your help anyway Heath
|
|
|
|
|
Hey
I´m trying to make a File Explore like windows explore. I get the Logical drives GetLogicalDrives and then iterate through them. At this point I´m using GetDirectories.
My problem is that I want to show all the drives, also if there is no media like a cdrom or floppy. But using GetDirectories on a:\ with no floppy inserted throws an exception I can't catch.
Please help I want to avoid this.
|
|
|
|
|
naxos wrote:
But using GetDirectories on a:\ with no floppy inserted throws an exception I can't catch.
I somehow doubt this.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
I am trying to create an manual and automatic application in one with windows interface. The manual/automatic switch is in a configuration file.
I have created a form with two buttons. Start and Cancel/Exit. The Start button starts a process that can take up to an hour. The cancel button cancels the process and Exit closes the application.
So far no problem.
When the application is in automatic mode. It should start the process and exit the application. (batch mode), BUT I want the form to show the processing information. Just in case the operator is watching.
Thanks for your help.
Patrick
|
|
|
|
|
|
The problem is that the form does not show while running the automatic processes.
For automatic I put Start1, Start2 and Exit in Initialize(), which are the same routines the buttons call in manual mode.
-P
|
|
|
|
|
Patrick Luijpers wrote:
The problem is that the form does not show while running the automatic processes.
I assume you mean the form is not responding, due to the process taken a long while.
Just fire the process off in a new thread.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Hi,
I'd like to know if it's possible to have a TreeView where some nodes have checkboxes and some other nodes don't.
And if it is possible, how can I do it..
Thanks in advance,
TomaHawK
|
|
|
|
|
Not with the TreeView in the .NET BCL, unless you extend it and override WndProc , dealing with a lot of the messages. See the SDK Documentation for the Windows Tree View common control about how much you'll need to override. You'll have to owner draw each tree node and add a property to your own TreeNode derivitive.
You might try looking for a third-party tree control. Infragistics has a pretty good one. You should also check ComponentOne.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I'm writing a (Very simple) application. Currently, the main form view consists of the common arrangement of a tree on the left and a rich view on the right. Each node on the tree causes a different rich view to appear on the right.
However, something is very odd.
If I have the cursor in the rich view, and change tree nodes, causing the new rich view to appear, from then on, I cannot close the app.
Application.Exit() works, but calling Close on the main form does not even trigger the Closing event.
I'm not overriding the Closing event or Closed, or anything related to that.
It only happens if the text cursor is in a rich view at the time the rich view is destroyed.
Clicking the X close button, hitting alt f4, nothing works. However, the program continues to behave as expected in every other way (I can continue to modify the rich views and switch between nodes.)
So what would cause Close to suddenly stop functioning? I'm removing the old rich view and replacing it with a new one each time a new node is selected, perhaps that has something to do with it?
|
|
|
|
|
Additional info:
If I watch for the Closing or Closed events, when in this above mentioned 'broken' state, NEITHER event ever even occurs.
If I use SPY++ to view what messages are occuring, I see WM_CLOSE is being sent to the app, but it does absolutely nothing with it...
It may be entirely unrelated to the rich view - what i'm doing is adding and removing user controls (which include rich views and tool bars of their own) from a panel inside the main window. Could that mess it up so badly?
?
|
|
|
|
|
This typically happens when an exception is thrown that screws up the application pump (such as an unhandled exception thrown inside WndProc . Basically, certain message stop being sent. I haven't found any more on it other than that (it all comes down to Windows Messages as you seemed to have guessed), but we are having a similar problem where certain unhandled exceptions (unhandled by the clients that is, but caught by my AppDomain.UnhandledException handler) cause the application to this as well.
I haven't had time to tackly the problem any more since I'm now working on several more improbable tasks with impossible deadlines ( ), so if you figure anything out - would you care to share on the forum (thus preserving your findings for future generations )?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
since I'm now working on several more improbable tasks with impossible deadlines
Simply gain additional time by cutting sleep out of the equation, you can always sleep when your 30. Maybe if you throw a little XML at the problem a solution will appear?
-Nick Parker
DeveloperNotes.com
|
|
|
|
|
I still can't figure this out.
Wouldn't an exception show up somewhere? I even tried putting the entire application in a TRY / CATCH block (heh), but nothing showed up.
|
|
|
|
|
You can't put an entire Windows application in a try-catch block. See, Application.Run that starts your application is a blocking call (the application pump loops and distributed Windows messages to the appropriate windows). If an exception occurs there but not in your code, it may not be caught. To do this, you must do as I did and stated in my first reply: handle the AppDomain.UnhandledException event.
In any case, this exception is not an app-crasher - it merely screws up the main UI thread but it continues to run.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
[in the MAIN:]
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
[later on:]
static void MyHandler(object sender,
UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
MessageBox.Show("Exception.");
}
This is almost straight from the MSDN library documentation. However, the UnhandledException never occurs (Even if I replace the messagebox with a console write, no console text appears), however the problem remains.
Perhaps its something else besides an unhandled exception.
|
|
|
|