I've been getting a very intermittent problem in a program. I know roughly what it is, and it is easy to get rid of, but I have no idea whether it is something I need to worry about going forwards, or how to solve it.
This program uses XNA to draw controls on a form. This drawing requires some things to exist for it to work, one of which is the windows handle of the control in question. This caused a problem (and a previous thread), because the windows handle wasn't always being created where I thought it was being created. The handle wasn't created when the control was created, but when the new control was first interacted with in any way. That proved to have a pretty simple solution. I just had to interact with the control early enough that the handle was around when the XNA stuff needed it.
The current error message is the same one, and the problem is the same. The windows handle appears to be initialized on first use, and first use isn't always when I expect it. However, there does appear to be a solid patter to the problem: It only happens when the computer has just been booted up, VS started, and the program launched from the debugger for the first time. I get the exception. Re-launch the program, and all is well, and will remain well until the next time it happens (which would be at least the next day, since it only happens when the system has just been started up).
I'm not sure that there is anything I can do about this, and I'm not sure that I should care. Gatherind data on the problem is hard to do because of the rarity of the problem. I have the feeling that it doesn't ALWAYS happen on first run of the project after boot, but the times that it doesn't happen on first run, I've always done certain things before running the project (I don't know what those certain things are, but they could be looking at the startup form in the designer, or something like that).
So, for a totally vague question: Does anybody know why a windows handle might not get initialized right away?
Heck, that may not even be the question. When a form is opened in the designer, some of the code behind the form is run to display the form. That, alone, changes the internal state of VS in some way. It may be that so simple a thing is sufficient to prevent this exception from happening, in which case it has no impact on the program itself, and is nothing more than a minor annoyance. It's a puzzle, though, and if anybody has any suggestions, I'd be interested in hearing them.
This program uses XNA to draw controls on a form. This drawing requires some things to exist for it to work, one of which is the windows handle of the control in question. This caused a problem (and a previous thread), because the windows handle wasn't always being created where I thought it was being created. The handle wasn't created when the control was created, but when the new control was first interacted with in any way. That proved to have a pretty simple solution. I just had to interact with the control early enough that the handle was around when the XNA stuff needed it.
The current error message is the same one, and the problem is the same. The windows handle appears to be initialized on first use, and first use isn't always when I expect it. However, there does appear to be a solid patter to the problem: It only happens when the computer has just been booted up, VS started, and the program launched from the debugger for the first time. I get the exception. Re-launch the program, and all is well, and will remain well until the next time it happens (which would be at least the next day, since it only happens when the system has just been started up).
I'm not sure that there is anything I can do about this, and I'm not sure that I should care. Gatherind data on the problem is hard to do because of the rarity of the problem. I have the feeling that it doesn't ALWAYS happen on first run of the project after boot, but the times that it doesn't happen on first run, I've always done certain things before running the project (I don't know what those certain things are, but they could be looking at the startup form in the designer, or something like that).
So, for a totally vague question: Does anybody know why a windows handle might not get initialized right away?
Heck, that may not even be the question. When a form is opened in the designer, some of the code behind the form is run to display the form. That, alone, changes the internal state of VS in some way. It may be that so simple a thing is sufficient to prevent this exception from happening, in which case it has no impact on the program itself, and is nothing more than a minor annoyance. It's a puzzle, though, and if anybody has any suggestions, I'd be interested in hearing them.