|
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
|
|
|
|
|
Hi,
here are some thoughts:
1.
seems you have a TabControl with one TabPage+WebBrowser added in Visual Designer; and inside newTabToolStripMenuItem_Click() you have code to add a TabPage+WebBrowser at run-time. This makes your first TabPage technically different from the future tab pages, not a very good idea:
Right now the first tab page has its WebBrowser kept in a variable webBrowser1 which is a class member of your Form; it is therefore the one that gets used in toolStripTextBox1_KeyPress(), no matter which TabPage is currently visible. The extra tab pages have a local variable, also called webBrowser1, but that only exists in the scope of newTabToolStripMenuItem_Click().
2.
almost all web browsers (e.g. FireFox) support tabs, and show a single TextBox for entering a URL; however the content depends on which TabPage is current. There basically are two ways to achieve this:
(a) really have a single TextBox and switch its content whenever the tab pages get switched;
(b) have a TextBox for each TabPage, all at the same Location, however all but one invisible. This might be easier.
3.
This is what I would do (assuming a Form called MyBrowser):
- with Visual Designer add a TabControl without Tab Pages to MyBrowser; and an invisible TextBox for URLs ("tbDummyURL").
- create a "BrowserPage" class that holds everything about a single tab page, including a TextBox "tbURL" and a WebBrowser "browser";
- create a variable MyBrowser.currentBrowserPage that holds the current browser page (initially null);
- create a method BrowserPage MyBrowser.AddTab ; it would instantiate and return a BrowserPage, add its TabPage to the TabControl, set its TabPage.Tag to itself, and set its TextBox.Location to tbDummyURL.Location without making it visible.
- create a method MyBrowser.ShowTab(browserPage) ; it would set currentBrowserPage.tbURL.Visible false (unless null) and browserPage.tbURL.Visible true.
Then at run-time probably immediately create and show the first tab; whenever some button gets clicked create and show an additional tab; etc.
refinement: if you have another button to close the current tab, you need to remove the TabPage, and show again the previous tab. The proper way would use a most-recently-used approach, which you can implement with a List<BrowserPage> in MyBrowser. Then ShowTab(browserPage) should remove browserPage from the list, and add it again, effectlively moving it (if it was already in the list) to the last position in the list. So, closing a tab would remove it from the list, and the now last entry, if any, should be shown.
This may be a bit much, I suggest you try it step by step. Ask again if you get stuck (but please use PRE tags, not CODE tags, for code snippets).
|
|
|
|
|
Thank you, that makes a lot more sense now, should be easy enough to change what's affected by the address bar with a tab index changed event or similar.
I'll let you know how I get on,
Thank you
|
|
|
|
|
you're welcome.
|
|
|
|
|
Well I am sad to say that I have usually avoided inheritance because I don't have a full understanding of it and/or I haven't yet found a good use for it.
So my newest learning project is a client / server (have been posting about it you may notice alot). A brief overview of what I have been doing is passing my custom object over TCP. My custom object is a seperate DLL project.
Erik didn't like it but to be honest I haven't came up with a better way or fully understood. AFter reviewing hie article that he pointed me to I'm just wondering if I should be using a interface and/or inheritance.
Here is my Commons object:
[Serializable]
public class Commons
{
public Commons()
{
TimeStamp = DateTime.Now;
}
public enum Tasks
{
CHECKIN,
DISKDRIVE,
DRIVEINFO,
FAN,
MESSAGE,
PHYSICALMEMORY,
PRINTERS,
PROCESSES,
REGISTER,
SERVICES,
SOFTWARE,
ADD_CMD,
CLOSECD,
GET_ALL,
REBOOT,
OPENCD,
SHUTDOWN
}
public Tasks Task { get; set; }
public Tasks AddTask { get; set; }
public DateTime TimeStamp { get; set; }
public string AgentId { get; set; }
public string Netbios { get; set; }
public string IpAddresses { get; set; }
public string PhysicalAddresses { get; set; }
public string Message { get; set; }
public int LocationID { get; set; }
public Software[] Software { get; set; }
public Services[] Services { get; set; }
public DiskDrive[] DiskDrive { get; set; }
public DrivesInfo[] DriveInfo { get; set; }
public Memory[] Memory { get; set; }
public Printers[] Printers { get; set; }
public Processes[] Processes { get; set; }
public Fan[] Fan { get; set; }
}
Now those other classes look like this:
[Serializable]
public class Printers
{
public string PrinterName { get; set; }
public string PaperSizes { get; set; }
public string PrinterResolutions { get; set; }
public bool SupportsColor { get; set; }
public bool IsDefaultPrinter { get; set; }
public bool CanDuplex { get; set; }
public bool IsPlotter { get; set; }
}
So getting an idea of what I'm trying to do, I am wondering if a situation like this will best serve using a interface and/or inheriting a class? I get the idea, you implement a interface, you inherit a class.. but like I said I haven't put together a good use for something I'm trying to do.
Now what I am doing with this data once it reaches the server is inserting it into SQL. If a client gets the TASK == PRINTERS, then it will perform a lookup using WMI of all local printers, poopulate the Printers[] array and send back to the server. So server gets the TASK == PRINTERS and see the Printers[] array is populated and proceeds to insert that data into SQL.
Sorry if this question is kind of broad.
|
|
|
|
|