|
| 19 Oct 2011 02:00 PM |
I am posting this here, because the thread on Scripters forum got deleted.
Okay, I know there aren't alot of C Sharp scripters in here, but if there is, this is for you. How do you use threading? Like, wait() in Roblox. I've tried a lot of different things but for nothing. Some help here? |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 19 Oct 2011 02:04 PM |
I think using a wait() (Like in Roblox) is the same as it is in Java, Thread.Sleep(milliseconds)
<'+1 Post. Ujelly?'> |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 19 Oct 2011 02:05 PM |
I think using a wait() (Like in Roblox) in C# is the same as it is in Java, Thread.Sleep(milliseconds)*
<'+1 Post. Ujelly?'> |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:06 PM |
I know, it is Thread.Sleep, but somehow it does not work :o
|
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:06 PM |
| Thread.Sleep(); works? Wow I really need to try that. |
|
|
| Report Abuse |
|
|
myrco919
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
|
| 19 Oct 2011 02:08 PM |
| Ugh I don`t like making Timers. |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:08 PM |
| Timer isn't what I want, timer just repeats a method over and over again. |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:11 PM |
| Oh god, nevermind, Thread.Sleep() works perfectly fine for me. I think I used it wrong, so ya, thread closed. If you wanna post anyways, do it. |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:13 PM |
| Soul, What program for C# are you using? |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:16 PM |
| Microsoft Visual C# 2010 Express |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:17 PM |
| Oh. Because when I use that one the Error list says that theres no such thing of 'Thread'.. |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:18 PM |
You have to use this:
using System.Threading;
You should search the system a bit, or look for tutorials. |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Oct 2011 02:30 PM |
| o.o Wow some noob F5`ed this thread. |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:33 PM |
Ok since this is a sticky, lol, could someone debug this for me? :o
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
public static void Main(String[] args) { while (true) { check(); Thread.Sleep(1000); } }
static bool On = false; static bool ImageOpen = false;
private void button1_Click(object sender, EventArgs e) { if (On) On = false; else On = true; }
private void check() { if (On) { if (ImageOpen) { pictureBox1.Image = null; ImageOpen = false; } else { pictureBox1.Image = WindowsFormsApplication1.Properties.Resources.lolface; ImageOpen = true; } } else { pictureBox1.Image = null; } } } }
Output:
Error 1 An object reference is required for the non-static field, method, or property 'WindowsFormsApplication1.Form1.check()' C:\Documents and Settings\JP\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Form1.cs 24 17 WindowsFormsApplication1
|
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Oct 2011 02:35 PM |
| When you click a button, its supposed to flash an image to nothing and to a face every 1 second. |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Oct 2011 02:37 PM |
private static void check()
?
:D |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:39 PM |
Nope, sorry, it removes that error but gives 3 more errors.
Error 3 An object reference is required for the non-static field, method, or property 'WindowsFormsApplication1.Form1.pictureBox1' C:\Documents and Settings\JP\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Form1.cs 52 17 WindowsFormsApplication1
|
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:40 PM |
| The thing is, after that it can't access to pictureBox1. |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Oct 2011 02:43 PM |
*searches google for the error*
you apparently cant access non-static fields from static methods
you either need to have it be static, or create an instance of Form1
whatever that means |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2011 02:46 PM |
| Thanks dude! It was really worth googling :D |
|
|
| Report Abuse |
|
|