|
for(int i=0; i<(players.Length*2); i++)
{
// Do something
// Update the view
updateview();
// Wait
}
I am building a small cardgame.
i give each player a card and then i want to wait for a few seconds before giving next user thier card.
Iam pretty new to C# and havent got any luck when i tested making a thread...
In short;
How can i make a loop that waits for example 3 sec before doing the next lap.
Mrnoname
|
|
|
|
|
System.Threading.Thread.Sleep will sleep the entire thread for x milliseconds before continuing. Keep in mind that if this code is running in your form, the form will not respond to any windows command for that 3 seconds. If you want this to work properly, you should run this block of code in a new thread.
One other way to do this (without locking up the form) is to create a timer instead of a loop.
See the code below:
<code>
private int currentPlayer = 0;
private System.Windows.Forms.Timer t = new Timer();
public void BeginSetupCards()
{
this.t.Interval = 3000;
this.t.Tick += new EventHandler(t_Tick);
}
private void t_Tick(object sender, EventArgs e)
{
updateview();
this.currentPlayer++;
if(this.currentPlayer >= (this.players.Length * 2))
{
this.t.Stop();
}
}
</code>
Keep in mind that there are much better ways of doing this (which are a little more advanced) such as custom threading or even better asynchronous methods. If you would like some examples of the more advanced methods, please reply and I'll be glad to show you.
|
|
|
|
|
XRaheemX wrote:
updateview(); // It's a bad idea to update the form view from within a timer. You should create an event delegate for the update and kick it off using Form.Invoke;
It actually is fine to update controls from the tick event of System.Windows.Forms.Timer, as the event handler runs on the message pump thread.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thats right (now I remember ), while learning about events and threading I made myself think that the timer ran in a different thread so I could get used to the idea... guess that was a bad idea. lol
|
|
|
|
|
Keep in mind that there are much better ways of doing this (which are a little more advanced) such as custom threading or even better asynchronous methods. If you would like some examples of the more advanced methods, please reply and I'll be glad to show you.
Like to know how...
Tried thread.sleep(3000);
But the result was that the form dident show for 3 seconds... not what i had in mind
|
|
|
|
|
Use the a timer, the Windows.Forms.Timer should be fine. Start it after playing the first card, play the second and subsequent cards on the Timer.Tick event (you'll need to keep track of which card is supposed to be played) and when all the cards are played just stop the timer again.
|
|
|
|
|
I know you're just trying to help, but did you read the replies before you posted? This is exactly what I posted an hour ago...
|
|
|
|
|
Your message wasn't there when I posted mine. I saw it right afterwards.
I gave the same answer so why do you need to be such a jerk about it?
|
|
|
|
|
I wasn't being a jerk, hence me putting "I know you're just trying to help". I apologize for my post to you and retract what I said. What I am wondering though is why my post didn't show up on yours when it was a full hour before?? Perhaps the code project is running a little slow? In any case, my goal here is not to make enemies so I am truly sorry.
|
|
|
|
|
Hello,
Is there an equivelent IRR function in C#, to the one in VB? Does anyone knows of any resources, etc.. that will help me to write the IRR function in C#?
Thank you.
|
|
|
|
|
You don't have to rewrite it and it's not part of Visual Basic.NET (the language anyway). It's part of the Microsoft.VisualBasic namespace, in the Financial class. Just set a .NET reference to the Microsoft.VisualBasic.dll and import the namespace.
If you really want the source code for the function, you can use Lutz Roeder's .NET Reflector to see the source in C# or VB.NET.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks, Great Help
How can I see the code using Lutz?
Thank you
|
|
|
|
|
Hi folks,
Can any one guide me for a way to change "Startup Type" of windows service in runtime. Any pointer will be of great help.
Thanks in advance.
Regards
Rajeev
|
|
|
|
|
|
Hi,
Is there any API for powerpoint file programming in .net? If using Office Interop assembly, is it necessary to install office in the system? Since i would like to implement a server for powerpoint file retrieval and do not like installing office in a server.
Thanks
|
|
|
|
|
Yes, the Office PIA's require Office on the system that you're using them on.
And no, it doesn't look like there's any PPT SDK for .NET. Since you're building a server for "powerpoint file retrieval", is there a reason you're not just letting people download the PPT file via HTTP or FTP?
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Hello,
Of course, I would not like others downloading the powerpoint files from the server without the access right.
I heard from my friend office should not be installed on a server. Is it true? That means I cannot install office on the server so I cannot use the office interop assembly?
There is an alternative that I could turn a powerpoint file to an XML file. Is there any API for .net programming to do such thing? I have found a api call PowerML but it is a java library.
Thanks
|
|
|
|
|
In VS2005 Beta the oersonal web kit is available, I have loaded and CTR+F5 the I closed the page and tryed to add a user as it says in the doc, the page is loaded and after I click the Security tab this error is shown:
"There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Exception has been thrown by the target of an invocation."
How can I FIX THIS?
"Tow things are infinite,
the Universe and human stupidity,
and I am not so sure about the former!"
Albert Einstein
|
|
|
|
|
I have installed the Visual Studio 2003 FULL With MSDN (ORIGINAL NOT CRACKED , Office 2003PRO FULL.
After installing Office i have insatlled the MSDE form OFFICE CD, IIS is installed.
Then: Microsoft Office Access 2003 Developer Extensions (English)
Microsoft Visual Studio® Tools for the Microsoft Office System 2003 (English)
Then: SQL SERVER 2000
Then: VS2005 Beta (Full install).
Now the problem is in 2003 when I try to create a Office Project it loads my prj then if I try to execute it Word is opening and after 1 sec it closes...
In 2005 after creating the proj and F5 the Word is Oppend and an error appears in VS:
FileNotFoundException was unhandled
"Could not load file or assembly 'WordDocument, Version=1.0.2110.20427, Culture=neutral' or one of its dependencies. The system cannot find the file specified."
If I close the VS and try to open the WordDOC it loads and an error appears:
"Office document customization is not available"
"The customization assembly could not be found or could not be loaded.
You can still edit and save the doc. Contact bla bla..."
PLS HELP ME I REALLY NEED IT TO WORK
"Tow things are infinite,
the Universe and human stupidity,
and I am not so sure about the former!"
Albert Einstein
|
|
|
|
|
There are some issues when using Visual Studio Tools for Office and .NET 2.0 at the same time. VSTO is very picky with respect to the runtime it uses. My recommendation would be to uninstall VS2005 or, to fire up a Virtual Machine (in Virtual PC, since you've got MSDN) and try installing just VS2003 and VSTO in it.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
I just want to hide some columns on my data grid (dynamically). I have my data grid, it's loading the data just fine, and all I want to do is make a column hidden.
Here's what I wrote:
this.dgClaimsExperience.Columns(1).Visible = false;
But C# tells me that System.Windows.Forms.DataGrid does not contain a definition for columns.
So... how do I do it?
Thanks.
The ends can never justify the means. It is the means that determine the ends.
|
|
|
|
|
DataGrid indeed does not contain a columns collection.
There are a couple of ways you can handle this, one way is to remove the DataGridColumnStyle for the column you want to hide from DataGrid.TableStyles. The tricky part is that if you want to put it back in it will move to the end of the list and you'll have to rearrange all the other columns (by removing them from the list and then adding them back in the right order).
Another way is to set the width of the column (through the DataGridColumnStyle) to zero, but I think the user can still resize it and I think it they can still tab to the column.
|
|
|
|
|
Thanks for the suggestions. I think removing the DataGridColumnStyle will work, because in the instance of the form where the data grid is located, I'm never going to want to add the column back in.
If you get a chance, post a code snippet for me, otherwise I'm sure I can figure it out on my own.
I'd just like to state for the record that I think that DataGrid [i]should[/i] contain a columns collection. It would be useful.
Thanks for the help - I'm the only "programmer" (I'm really a mathematical-statistical analyst) in my company so there's no one for me to take my sinple, dumb questions to in person.
-stormin
The ends can never justify the means. It is the means that determine the ends.
|
|
|
|
|
Something like this should work:
<br />
DataGridColumnStyle dgcs = MyDataGrid.TableStyles["MyTableName"].GridColumnStyles["MyColumnName"];<br />
MyDataGrid.TableStyles["MyTableName"].GridColumnStyles.Remove(dgcs);<br />
It's a little more efficient if you keep a reference to the table style and column style objects that you're using so that they don't have to be looked up each time, but the above code should work.
|
|
|
|
|
I'm a new to xml serialization and I haven't found much joy on the web.
How do i specify arbthree both nullable and a nonNegativeInteger? Or in otherwords have more then 1 attribute type?
i tried using them together like the following but I get a compile error
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
[System.Xml.Serialization.XmlElementAttribute(DataType="nonNegativeInteger")]
public string arbtwo;
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public string arbone;
[System.Xml.Serialization.XmlElementAttribute(DataType="nonNegativeInteger")]
public string arbtwo;
public string arbthree;
|
|
|
|