Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

My problem is that 2 instances of form1 are starting when I load my program. The problem occurs when starting the form from a Sub Main() contained in its own class.

 

My main question is, do you still use form_load if you start your form from Sub Main() or does this cause problems?

 

Thanks!

Posted
What are you using Form_Load for? If you're creating and showing an instance of your Form1 in Sub Main() AND also in Form1's .Load, you will get two forms. Unless you're preforming some task that has to be done BEFORE you show Form1, I would just set Form1 as the Startup object in the project properties. It's easier and no code! ;)
Being smarter than you look is always better than looking smarter than you are.
Posted

Thank you for your help,

 

I actually do have to perform a task before form1 loads. I made the Sub Main() because I needed to perform a Try...Catch statement before starting Form1. Is there a work around for this? For instance, should I put the code in the form_load event of Form1 in the Sub Main() and remove the form_load event from Form1?

Posted (edited)
Everything in the Form_Load is done before the form shows. Try putting everything in the form's Load event, set the form as the startup object for the project and don't use Sub Main(). If the process in your Error Handler catches something, just close the app (or take another appropriate action...) Edited by Mothra
Being smarter than you look is always better than looking smarter than you are.
Posted

Tried that... But after I close the form1 while THIS .ocx I'm using is still processing something, it throws an exception concerning the disposal of Form1 and when I choose to "debug" it in VS it goes to the code at the top Form1 that was generated by the Windows Form Designer where it says something like "Friend Classs" Form1 (I'm at work right now so I'm not really looking directly at it). The only way I could prevent this was to start the form from the Sub Main(), but now it's giving me this strange duplicate form problem. So if you know of anything I might be able to do I would be very greatful!!

 

Thanks!

Posted

Is there a command opening Form1 in the Sum Main() AND in Form1's load?

 

Can you maybe post the code?? It may help to see what's going on.

Being smarter than you look is always better than looking smarter than you are.
Posted

Here is Form1 and the Sub Main() in a class file named initialize so you can get some idea of what I'm trying to work with. Be warned though... the code is not pretty.. this is my first .net project and was also my first and only VB6 project. But I'm trying so here it is:

 

I should also mention something that I just noticed. The form duplication problem only occurs when I supply the command line argument "RSSYNCME" which is handled at the end of the Form_Load section.

 

Good Luck and Hope You Can Help! Thanks

form1 and init class.zip

Posted

Actually after a little more testing, it seems to happen when the sync_click event is fired.... either by the "RSSYNCME" command line argument, or by hitting the "Synchorinize" button on the form.

 

It must be something in the sync_click event that is actually causing this to happen.

Posted

I think it may have something to do with the multiple calls of the DoEvents method. If you're trying to let the user(s) still interact with the form while those processes are running, I would look into using seperate threads (it may require a little research and a little rework but, it may work a little better for you).

 

Also, you should always have Option Strict On. It will save you a boat load of troubles....

Being smarter than you look is always better than looking smarter than you are.
Posted

After commenting out the DoEvents the problem was still occurring. I determined that the problem was actually multiple calls of this line:

 

Form1.DefInstance.overallprogressbar.Value = 0

 

Also I will check out seperate threads, because you're right about the multiple DoEvents, they were put there to let the user interact with the form while it was running, however they really haven't been doing that great of a job of achieving this.

 

I really appreciate your help with this problem, Thank You!

  • Administrators
Posted

You may find some of the problems are down to the form having been migrated via the wizard. If you check in the converted code it is still using a lot of VB6 / COM controls and API calls which could be removed or changed to the .Net equivalents.

In fact the overallprogressbar control is still the VB6 ActiveX control rather than the .Net equivalent.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Administrators
Posted

Most of these controls already exist in .Net and can be found on the standard .Net toolbox. The wizard just doesn't convert the code to use the new controls.

With some you could simply delete the old control and replace it with the new control - just rename it to have th old controls name. Other controls do behave differently though.

 

The common dialog functionality and the progress bar could be replaced with .Net equivalents. Not sure about the skinner or the SregoCETPx1 control though (what do they do?).

 

Also the code to access the registry could be converted to use the Microsoft.Win32.Registry class instead, sleep could now use system.Threading.Thread.CurrentThread.Sleep instead. If you are running VisualStudio 2003 you get a folder browser control so you could remove all the interop stuff as well.

 

Not looked much further but what are you using CoTaskMemFree, lstrcat and SendMessage for?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
You know, I was looking for references to Form1 and it never even dawned on me that there was so much 6.0 compatibility code there.
Being smarter than you look is always better than looking smarter than you are.
Posted

The skinner was a vb6 activex control that allowed you to skin forms in a relatively easy way and the. SregoCETPx1 is also an activex control that lets a desktop app communicate with a Windows CE device such as a pocket pc. The sendmessage is being used in the Form_Load event to close any current instance of the program that is already running and CoTaskMemFree and lstrcat are being used in the "Browse for folder function".

 

Since I've just started converting this project over to .net, I've mainly just been trying to get it to work by whatever means necessary first and then upgrading as much of the code as possible to .net after that.

 

Thank you both for your help though, I really need it at this point as I'm feeling a little lost still with .net!!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...