|
Also, please explain why this "will be weird", because I didn't notice anything "weird" ...
|
|
|
|
|
Well, Application.Run is traditionally used from the main() entry point to the application. It creates a standard message loop on the current thread which then responds to user input and rendering requests and the like.
It's certainly normal to only have one such message loop, so using two (concurrently) opens up the dubious world of not having a single GUI thread. I've not seen it done before (except in modal dialogs etc.) And although it *may* be possible to use it, its certainly not the correct approach IMO.
You might end up with MTA/STA problems maybe as well.
Regards,
Rob Philpott.
|
|
|
|
|
But that was the purpose: I wanted to create a thread that contains another form while the other was currently busy.So I could show an animated gif in front of the form that is busy...
This seemed to be working great, except that if u minimize or moved the 'busy' form, the form in the new thread with the animated gif stays on screen, so I thought by setting the mdiParent would solve this, but apparently this can't be done...
I will change my design and let the main form do its work async so I can just put a picturebox in front till the work has been done or something ...
|
|
|
|
|
Also thanks for your input
|
|
|
|
|
No problem. I think that's the correct approach to go. You may be familiar with the notion of 'only the thread that creates a window can access it'. This means that you can never create another window on a seperate thread then make that a child of one on another.
If the two windows are completely seperate, you could use two Application.Run()s, although I'd explicity create a thread to do this and call that on it.
Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: his means that you can never create another window on a seperate thread then make that a child of one on another.
This makes a lot of sense. Thank you !
|
|
|
|
|
Because you cannot do UI stuff, like creating forms and showing them, on anything other that the app's startup thread, also known as the UI thread.
I do NOT care that "it works for me!". You or, more importantly, your customers WILL eventually find a problem that only shows up under certain circumstances that you're not going to be able to duplicate and, if you do, will be very weird and nearly impossible to track down.
You just do NOT do it if you want your app to be as stable as possible.
You're going about this backwords. You do not keep the long-running work on the UI thread in your main form. You move THAT work to a background thread, freeing up the UI thread to handle putting up a "progress" form and updating it.
UI stuff stays on the UI thread. Actual work stuff goes on background threads.
Using an MdiParent form to do this is just silly.
|
|
|
|
|
Dave Kreskowiak wrote: You're going about this backwords. You do not keep the long-running work on the UI thread in your main form. You move THAT work to a background thread, freeing up the UI thread to handle putting up a "progress" form and updating it.
I already had come to that conclusion if u had read everything.
Dave Kreskowiak wrote: Because you cannot do UI stuff, like creating forms and showing them, on anything other that the app's startup thread, also known as the UI thread.
It IS possible, I had a form popup in front of my main form , created on another thread, with the Application.Run , and I had never ever got an error or something 'weird', because all it did was simply popup, show animated gif and close again.And I have this tested for weeks now...
|
|
|
|
|
ddecoy wrote: It IS possible
Re-read what I posted. I said you may not get any problems, but you will eventually find some issue. Not essentially in this app, but if you continue to use this technique in other situations, you will find problems.
|
|
|
|
|
Hi everyone
My class implementation like
base class : DatabaseWrapper
1) It is abstract one
2) Contains method common to derived class (e.g. select,insert,update,delete)
Derived class :
1) ExcelWrapper
override the common method which are in base class.
2) SqlDatabaseWrapper
- override the common method which are in base class.
- Also has StartTrancation,Rollback and commit method
- also has executestoreprocedure
Now my implementation work fine when
i create object like
SqlDatabaseWrapper sql = new SqlDatabaseWrapper();
sql.StartTranction();
.
...
...
sql.Commit();
but now i have implement like
DatabaseWrapper sql = new SqlDatabaseWrapper();
sql.StartTranction();
.
...
...
sql.Commit();
but i am not able to get the methods.
How we can solved this using Strategy design pattern.
Yogesh Pekhale
pekhaleyogesh@gmail.com
|
|
|
|
|
Sounds to me what you want is an interface, not a design pattern
abstract class DatabaseWrapper
interface ITransactionalDatabaseWrapper
void StartTransaction();
void CommitTransaction();
void RollbackTransaction();
class ExcelWrapper : DatabaseWrapper
class SqlDatabaseWrapper : DatabaseWrapper, ITransactionalDatabaseWrapper
ITransactionalDatabaseWrapper transactionalDb = new SqlDatabaseWrapper();
|
|
|
|
|
Hi J4amieC
Thanks for quick response....
You ans sounds logical, in fact i tried workout well !!!!
but my application requirement is that from base class i need to access the method like
DatabaseWrapper db = new SqlDatabaseWrapper();
i am having another solution of it using Strategy design pattern like
i have
1)ItrnactionalInterface in that startTraction.....
Then i have two concrete class
2)TrancationalDatabase : ItrnactionalInterface // implements transaction
3)Non TrancationalDatabase : ItrnactionalInterface // throwing exception
now in base class i defined it as
abstract class DatabaseWrapper
ItrnactionalInterface tr
// here i had method
void StartTranction
{
tr.StartTranction();
}
and in SqlDatabaseWrapper
tr = new TrancationalDatabase ();
and in ExcelDatabaseWrraper
tr = new NonTrancationalDatabase();
So when i do like :
DatabaseWrapper db = new SqlDatabaseWarpper();
db.StartTransction() // this will call the method from TrancationalDatabase
and if i
DatabaseWrapper db = new ExcelDatabaseWrraper();
db.StartTransction() // this will call the method from NonTrancationalDatabase
This working fine.. according to the strategy design pattern....
but the problem is the object of Transaction which i create in TrancationalDatabase
that i have to use in the SqlDatabaseWarpper.
Now even we can implement as property and access this....
but the problem is come when i am having OracleDatabaseWrapper, MySqlDatabaseWrapper....
Can you suggest any think how i can do this?
Yogesh Pekhale
pekhaleyogesh@gmail.com
|
|
|
|
|
Firstly, and perhaps contentiously I'd forget about the Strategy Pattern. It doesn't event warrent having its own name. (This is just containing a polymorphic base class or interface in another class and providing a method therein to switch the type instantiated). Design patterns usually create more confusion than good.
The trouble you've got is that you don't have a consistent interface on your different derived classes, therefore they cannot be switched in and out. You've got two options, either extend the base class to include the child's additional methods (and provide empty implementations in other children where the method is not applicable) OR somehow call those methods from within those defined in the base class.
If neither of those solutions is applicable, you'll have to treat the two child classes individually with type testing and casts.
Regards,
Rob Philpott.
|
|
|
|
|
Hi Rob thats great (Y)
But it will not woke if we more than one database wrapper...
like SqlDatabasewrapper if we have Oracle,Mysql and etc....
Yogesh Pekhale
pekhaleyogesh@gmail.com
|
|
|
|
|
Why recreate the wheel, there are already data access frameworks that do this. Have a look at the Microsoft Enterprise Library Data Access Application Block[^]. The source code is also available for you to review how it was implemented and you can extend it to cover any other needs.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Mark...
Thanks for the Information...
Ya great
I will have close look on this
Yogesh Pekhale
pekhaleyogesh@gmail.com
|
|
|
|
|
Hi Mark
This will work for only MS-SQl ?
What will in case Oracle or MySql?
Yogesh Pekhale
pekhaleyogesh@gmail.com
|
|
|
|
|
RTFM! The EntLib DAAB supports many databases.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I have dynamically created sets of radio button in different group boxes to represent possible answers to various questions like below. Now i want after the user has selected the correct answers, and clicks the "Done" button,the application is able to know which answers where selected. I am suspecting that i need an event for this but i do not know how to make such to handle this situation. Please assist.
string[] examsQuestions = { "What does OOP stand for?",
"Which control can be used in a layout for a form?",
"Which of the below languaages is not part of the .Net initiative" };
string[,] answers = { { "Object Oriented Prog",
"Only Other People",
"Oportunity Oriented Programming",
"Only Onntological Possiblities" },
{ "TableLayoutPanel",
"RowLayoutPanel",
"ColumnLayoutPanel",
"GridLayoutControl" },
{ "C#",
"J#",
"K#",
"F#" }
};
string[] correctAnswer = { "K#"};
private void LoadItems()
{
for (int i = 0; i < examsQuestions.Length; i++)
{
GroupBox gb = new GroupBox();
gb.AutoSize = true;
tbp.Controls.Add(gb);
TableLayoutPanel tbp2 = new TableLayoutPanel();
tbp2.ColumnCount = 1;
gb.Controls.Add(tbp2);
Label newLabel = new Label();
newLabel.Text = examsQuestions[i].ToString();
newLabel.AutoSize = true;
RadioButton rdb1 = new RadioButton();
rdb1.AutoSize = true;
rdb1.Text = answers[i, 0].ToString();
RadioButton rdb2 = new RadioButton();
rdb2.AutoSize = true;
rdb2.Text = answers[i, 1].ToString(); ;
RadioButton rdb3 = new RadioButton();
rdb3.AutoSize = true;
rdb3.Text = answers[i, 2].ToString(); ;
RadioButton rdb4 = new RadioButton();
rdb4.AutoSize = true;
rdb4.Text = answers[i, 3].ToString();
Control[] ctrl = { newLabel, rdb1, rdb2, rdb3, rdb4 };
tbp2.Controls.AddRange(ctrl);
}
}
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
U can check which button is "checked" when u click on the "Done" button?
or
if u want event,
Declare a variable named answer,
public string answer;
RadioButton rdb1 = new RadioButton();
rdb1.AutoSize = true;
rdb1.Text = answers[i, 0].ToString();
rdb1.Click += new EventHandler(button_Click);
private void button_Click(object sender, EventArgs e)
{
RadioButton button = sender as RadioButton;
answer = button.Text;
}
|
|
|
|
|
Hi,
1.
you don't really need radiobutton events for this, as you already are using a "Done" button; all you need to do inside the buttonDone_Click handler, is interrogate those radiobuttons, maybe like so:
for(int i=0; i<tbp2.Controls.Length; i++) {
RadioButton rb=tbp2.Controls[i] as RadioButton;
if (rb.Checked) Console.WriteLine("RadioButton "+i+" was checked");
}
2.
I would do a couple of things differently, such as:
- instead of using some 1-dimensional and 2-dimensional array of strings, I would create a little Question class, that holds one question, all possible answers, and the correct index. It is more object-oriented that way.
- Then add instances of Question to a list of Questions.
- This would allow for a variable number of answers per question, provided you generate your RadioButtons also in a foreach loop, instead of with straight code.
- and I would consider storing all questions in a database...
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
C# Coding WindowsApplication :
1) How can I have Log for error in try catch with this informations
1.Error Name :<br />
2.Form Name:<br />
3.Function Name that error occurred :<br />
4.Date_Time when error occurred :
2) Where I save this log info.
I mean shall i save them in XML or word File ?
modified on Thursday, February 4, 2010 4:38 AM
|
|
|
|
|
|
I wanna this log for windowsApplication ?!
So Please HELP !
|
|
|
|
|
|