3

I have a project of two Winform and I want to run the application by alternate form. In program.cs file there is:

Application.Run(new Form1()); 

That means the Form1 will execute as main form or startup form of application. Is it possible to change it programmatically by some time limit or days limit? I mean after two days it will execute Form2 as startup form. Like below:

Application.Run(new Form2()); 

Is it possible?

1
  • you could do this by keeping a track of when the application was opened and in which Form (possibly using a text file). Before loading the form, read from the text file and switch the form to load accordingly. Commented Feb 25, 2011 at 14:10

3 Answers 3

7

Sure, that's no problem:

var startDate = ReadStartDateFromFile(); if(DateTime.Now.Subtract(startDate).TotalDays < 2 || startDate == new DateTime()) Application.Run(new Form1()); else Application.Run(new Form2()); 

The method ReadStartDateFromFile reads the date of the first start of your program. If it has never been started before, it returns new DateTime().
If you want to use this as a way to implement a shareware mechanism, consider using an obfuscator, otherwise, it is very easy to crack. Additionally, you should encrypt the file, you write the start date to. Additionally, consider a setup, that creates that file with a dummy date. If someone simply deletes the file, you should consider that a security breach and directly show Form2.

Thanks to Mark for the great discussion in the comments!

Sign up to request clarification or add additional context in comments.

11 Comments

@Daniel Hilgarth, I wants to give days limit like after two days
@Daniel, @Mahesh: if you store something like this in a text file, I would recommend encrypting it in some way; otherwise, a user could just edit the text file and set the date to some point in the future (thus giving them more time).
@Daniel: true, but if you use 128 bit or higher, it's pretty darn close to two-way :-)
@Mark Avenius: As long as the obfuscator he is using, is doing a good job ;-) Because all info to decrypt and encrypt that file is in the program. BTW: In the current "implementation" it would be enough to simply delete the file... ;-) He would need a setup which creates the file and puts a dummy value in it and consider the scenario when the file is missing as a security breach and stop working...
@mahesh: I never released any shareware, so all my input is theoretical and simply based on common sense and my experience. Anyway, I think this is not the scope of the question. If my answer helped you with your question as you formulated it, please kindly accept it. If you want to ask something specific about shareware and protection from cracking, my suggestion is that you create a new question.
|
2
if(someRuleToDetermineIfForm1NeedsToRun) { Application.Run(new Form1()); } else if(someRuleToDetermineIfForm2NeedsToRun) { Application.Run(new Form2()); } else // default { Application.Run(new Form1()); } 

1 Comment

@mahesh, use this approach with a text file which stores the last form used.
1

Sure; you can do this:

if (condition1) Application.Run(new Form1()); else Application.Run(new Form2()); 

You can set the condition based on arguments passed in, etc.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.