|
i cant stop the execution...
I implement application which is based on decision tree.
you may have progress in breadth and in depth.
The main idea is to ask some question, if the answer is wrong, then the progress is in breadth (another question with the same difficulty level), here comes the recursion.
if the answer the user provide is correct, the progress is to the deeper level (higher difficulty level), this part works by loop.
i cant stop the recursion part in the middle of the progress.
when i started to implement it using console, it was easy, i just waited to user's input by Console.ReadLine() .
But now, i execute the algorithm from the ui, and after some question was generated, the ui updated, but the algorithm continue to run...
How do you think I can solve it ?
Thanks
modified on Sunday, December 5, 2010 5:26 PM
|
|
|
|
|
|
I yield to your yield
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
One can only hope you're unique then; two non-yielders would be a recipe for trouble.
|
|
|
|
|
and how it should help me ?
I've no iterations here...
|
|
|
|
|
IMO you could organize your current recursive calculations as if it was returning an enumerable list of results, while no such list ever gets created, all it should take is a yield return each time you have a new result; I look at it very much like a good old co-routine, if you're familiar with that concept...
|
|
|
|
|
i'm not familiar with the concept... any reference ? (google didn't helped much
and question about the yield, if i return each time calculated result, how can i send some data to the loop in order to stop it ? (let say correct answer was given)
Thanks
solved
modified on Saturday, December 11, 2010 11:20 AM
|
|
|
|
|
I created a little article on yield return here[^].
|
|
|
|
|
As Luc had been telling you yield is one way.
When using Console.ReadLine you were stopping the execution at some point correct? Essentially the same as calling the CancelAsync method on a BackgroundWorker object, again as Luc has suggested to you.
Again, IMO, you are making it much more difficult than it needs to be. You should be able to search breadth or depth from any point, not start at the beginning and wait for input.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
if i stop by Console.ReadLine() , the algorithm execution pause until user inserts the input. but the pause in specific recursion level.
after the input was inserted, the algorithm continue to run from the point it paused.
If i'll use CancelAsync and exit the thread, how i would be able to return to the exact point it was stopped ?
modified on Monday, December 6, 2010 5:05 PM
|
|
|
|
|
You have a poor algorithm if it must pause and wait for input and can't be reentered. IMO.
If you have to pause and wait for input then consider a Workflow, which from your description is what you should be using anyway. and I suggested to you yesterday.
http://msdn.microsoft.com/en-us/library/dd851337.aspx[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks for the link...
I'll read it
I assume i was need to use it any way, but a problem that Software Engineering in Uni is not so developed as it should be
|
|
|
|
|
if you want real synchronization between two threads, there are several tools available for that. Have a look at ManualResetEvent and AutoResetEvent classes. The pseudo-code could be:
public string WaitForUser(string message) {
...
myAutoResetEvent.WaitOne();
return someGlobalVariable;
}
public void myButton_Click(object sender, EventArgs e) {
string s=myTextBox.Text;
someGlobalVariable=s;
myAutoResetEvent.Signal();
}
|
|
|
|
|
Why on earth are you interacting with a console application from your WPF application? It sounds like you're really making problems for yourself.
|
|
|
|
|
Pete O'Hanlon wrote: Why on earth are you interacting with a console application from your WPF application? It sounds like you're really making problems for yourself.
I started with console, i'll move it to class library, and eventually i'll add a dll as a reference.
|
|
|
|
|
Do it right the first time and it will save you considerable work and problems.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Fair enough. That clarifies things a lot - for a moment, I was worried that you were asking questions in the console app. Anyway, Luc's suggestion is as reasonable as any other you're likely to get and the syntax is nice and straightforward.
|
|
|
|
|
igalep132 wrote: is it possible to fire events between threads ?
No.
Event handlers are executed on the thread that raise the event.
Although... what about avoiding cross-thread WinForms calls in events?...
|
|
|
|
|
i can`t make it in textbox
but in masked textbox i make the mask "00\0000" but user can enter month greater than 12 so i want to restrict this
or make valdation type the mask follow so user can`t enter > 12 or <1 or > this year
how ?
or can i make new type ("mm\yyyy")
|
|
|
|
|
Rather than a MaskedTextBox, why not use a DateTimePicker? That way the date is always valid, and it is obvious regardless of locale.
If you can't, then you would be best to use a ValidatingType property[^]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Hello Mohamed,
I don't know if it would fit in your scenario, but I'd advise you to try to use a datetime picker where Format property is set to custom.
Cheers
Manfred
|
|
|
|
|
thnx to all
ok .... how to create new type in C#
|
|
|
|
|
The maskedtextbox is described here[^], and it's usage is explained with a nice example at the bottom of that page. You'd set the mask to "00/0000" according the example, but I bet that it takes somewhat more customizing than merely changing the mask.
Mohamed Nabawy wrote: can i make new type ("mm\yyyy")
You could create a new class that encapsulates both a month and a year. The current edit-controls would not know how to interact with your class, unless you also create a TypeConverter .
I suggest you keep it simple and put two textboxes on that form; limit the keys that can be entered to numbers. Done
I are Troll
|
|
|
|
|
I'm trying to make a simple web browser with tab support and am having difficulty with getting pages to load in the right tabs.
I can make new windows and tabs and switch between them, however the web page typed in the address bar always loads in tab 0. I've never really used tab controls before and I'm kind of learning as I go.
I think I need somehow to almost dynamically name each new instance of webBrowser so they can be accessed individually but I don't know how to go about something like that.
Here's what I've got so far
private void toolStripTextBox1_KeyPress(object sender, KeyPressEventArgs e)<br />
{<br />
if (e.KeyChar == 13)<br />
{<br />
int currentTab = tabControl1.SelectedIndex;<br />
MessageBox.Show(currentTab.ToString());<br />
webBrowser1.Navigate(toolStripTextBox1.Text);<br />
}<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
webBrowser1.Navigate("http://www.google.co.uk");<br />
}<br />
<br />
private void newWindowToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
Form nextWindow = new Form1();<br />
nextWindow.Show();<br />
}<br />
<br />
private void newTabToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
TabPage nextTab = new TabPage("Google");<br />
tabControl1.TabPages.Add(nextTab);<br />
tabControl1.SelectedTab = nextTab;<br />
WebBrowser webBrowser1 = new WebBrowser();<br />
nextTab.Controls.Add(webBrowser1);<br />
webBrowser1.Dock = DockStyle.Fill;<br />
webBrowser1.Navigate("http://www.google.co.uk");<br />
<br />
<br />
}
Thank you for any help
|
|
|
|