|
|
friends i m having problem in displaying the form in a loop:
do
{
this.boardRenderer.DisplayBoard(gameBoard);
<other code>
}while(<the game doesnt ends>)
the DisplayBoard function draws on the form but when it is called in from a loop, the main form is not displayed until the processing of the loop is over (END OF GAME IN MY CASE :'( ) how can i make it display the form while processing other code?? PLZZZZ HELP!!
|
|
|
|
|
That is normal, the repaint happens in the same thread. You will need to have a worker thread that draws on the form using delegates.
I am sure there is a tutorial here on code project.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
-- modified at 16:05 Monday 5th June, 2006
|
|
|
|
|
Thanx michel but the thing is i only want to draw the board whenever the player makes a move not randomly so will worker thread be usefull then also?
regards
|
|
|
|
|
|
A link to a very good article on the subject: [^]
Read thoroughly!!!
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
HEY THNX BUDDY.. U ROCK
|
|
|
|
|
|
If the game board really needs to be updated a zillion times a second, then you might want to consider triggering the rendering logic via a Timer. If the frequency of invalidation is not that common, then you might just want to handle the Paint event of a Panel and render the game board there.
Josh
|
|
|
|
|
I have a routine that enables me to update a textbox even when called from a non-ui thread.
delegate void AppendTextCallBack(string text);
private void AppendText(string text)
{
if (this.textBoxStatus.InvokeRequired)
{
AppendTextCallBack CallBackAppendText = new AppendTextCallBack(AppendText);
this.Invoke(CallBackAppendText, new object[] { text });
}
else
{
textBoxStatus.AppendText(text);
}
}
It works just fine, the problem is that I am repeating it and others like it in every single form in my app. I'd like to refactor and have a single function in some common location that all the forms can use. I'd prefer not to create whole new class, but...
Any suggestions?
|
|
|
|
|
Sorry about the code formatting, it looked fine before the post.
|
|
|
|
|
nicknotyet wrote: I'd prefer not to create whole new class, but...
That really limits your options.
You could implement those helper methods as public static members of one of your Form-derived classes, and then call into those methods from the other Forms. But that is weird, because there's probably no justifcation for that one Form-derived class to have the methods, and not some other Form-derived class.
I'd say bite the bullet and spend the extra 6 seconds needed to create a static utility class.
Josh
|
|
|
|
|
Yeah, it really wasn't that much work.
Making it static was the difference as it obviated me of the need to instantiate the class all over the place.
Thanks
NIK
|
|
|
|
|
If the loss of type safety doesn't bother you much, you could factor it out into a generic routine like this
private void MarshalToUIThread(Delegate d, params object[] arr)
{
if (this.InvokeRequired)
this.BeginInvoke(d, arr);
else
d.DynamicInvoke(arr);
}
You would then call it like MarshalToUIThread(new AppendTextCallBack(AppendText), new object[]{text});
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I am working on an app and having issues with my DAL and connectivity. Can anyone suggest a site with a sample app which details how to do this?
Guess this might help... using VS.NET2005 in conjunction with SQL2K5
-- modified at 14:37 Monday 5th June, 2006
|
|
|
|
|
Can you should be more specific about the type of problem you are having? You might get more replies that way.
Josh
|
|
|
|
|
I have data access/population of a grid via drag and drop but now I am trying to create a data access layer with provided stored procs to populate grids as opposed to drag and drop. So my issue is creating a DATAAccess class with the SQLConnection to be called by various forms.. then once the SQLConnection is made I need to call storeProc1 for example.
So 1. I need an example of a generic dataaccess class to create the connection
2. be able to call the dataaccess from a from
3. be able to call a stored proc to populate a GRID
|
|
|
|
|
This is basic data access work. You should be able to find tons of samples, snippets, etc. on CodeProject. If all else fails, Google.
josh
|
|
|
|
|
I have 2 objects, one is the form ( form object), the other is an object (updating object) responsible for updating it's local DataTable.
Each of these objects runs in its own thread.
In form object I have a datagrid which is bound to the local table of the updating object.
When I run the program, if I don't disable the grid, it can run only 2 loops. If I disable the grid, I can run some dozens of loops.
If I replace the grid by another control ( combobox for example), the application runs smoothly.
Can you explain me why this happen? Thank you very much.
I suspect this problem relate to the Multi-thread enviroment.
|
|
|
|
|
In Windows a control should only be modified from the thread which created the control. Make sure that you are only touching the grid from the main UI thread. You can check that by inspecting the value of InvokeRequired on the grid. If you are updating the grid from a different thread, be sure to marshal the call over to the UI thread via the BeginInvoke method on the grid.
Josh
|
|
|
|
|
I didn't touch the control. The updating thread update the datatable. And the datagrid is bound to the datatable. That's all.
Then I kiss Ur eyes and thank God we're together
|
|
|
|
|
fan wei fang wrote: Then I kiss Ur eyes and thank God we're together
:->
|
|
|
|
|
I forgot to delete my signature man.
Then I kiss Ur eyes and thank God we're together
|
|
|
|
|
Hi,
I want to convert txtboxvalue (dd/mm/yyyy) as (mm/dd/yyyy).How to do this?
Please help me.
Thanks in advance
|
|
|
|
|
DateTime.ToString has an overload which takes a format string. The .NET docs list the format strings for dates. That should be what you need.
Josh
|
|
|
|