System.Threadin.Thread.Sleep HELP :S menu

Shout-Out

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    System.Threadin.Thread.Sleep HELP :S

    Ok, im trying to make a new spambot in C# but i have this problem with System.Threading.Thread.Sleep. Heres my code.

    Code:
    string Intervalw = textBox1.Text;
    System.Threading.Thread.Sleep(Intervalw);
    Something like that is needed, but i get 2 errors.
    Code:
    1:
    
    Error    1    The best overloaded method match for 'System.Threading.Thread.Sleep(System.TimeSpan)' has some invalid arguments    C:\Users\Sørensen\Documents\Visual Studio 2008\Projects\Krilleres iZpams C\Krilleres iZpams C\Form1.cs    42    17    Krilleres iZpams C
    Code:
    2:
    
    Error    2    Argument '1': cannot convert from 'string' to 'System.TimeSpan'    C:\Users\Sørensen\Documents\Visual Studio 2008\Projects\Krilleres iZpams C\Krilleres iZpams C\Form1.cs    42    47    Krilleres iZpams C
    Im a beginner at C# so i dont know what i should to, google didnt help me so i was hoping you would be able to. Please dont flame me for being a nab :P

    System.Threadin.Thread.Sleep HELP :S
  2. #2
    Clain's Avatar Banned
    Reputation
    179
    Join Date
    Jan 2008
    Posts
    1,396
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to typecast intervalw from a string to a "TimeSpan", can't post any code because I'm not on my laptop atm, perhaps someone else will.
    Last edited by Clain; 03-03-2009 at 04:08 PM.

  3. #3
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont understand O.o As i said im a complete noob, can you just make an example? Just a short one like the one i made in the post :P

    Edit: Ok, gonna try google it to get some help. Hopefully ill find out how to do it. I want to post a better bot this time ^^
    Last edited by Krillere; 03-03-2009 at 04:13 PM.

  4. #4
    Clain's Avatar Banned
    Reputation
    179
    Join Date
    Jan 2008
    Posts
    1,396
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    TimeSpan span = TimeSpan.Parse(TextBox1.Text);
    Thread.Sleep(intervalw);

  5. #5
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Omg. Im just gonna try this, if it works you just got yourself some rep! :-)

  6. #6
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. Seems like it works. Now i got another question ( Sorry )

    In AutoIt you could just write Time * 1000 so that you wouldnt have to write Miniseconds in the spambot, what do i have to write in C#?

    I know, im a nab..

  7. #7
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    int sleepTime = int.Parse(textBox1.Text) * 1000; // Add *60 if you want to change it to minutes, instead of seconds.
    Thread.Sleep(sleepTime);
    That assumes textBox1.Text is something like '5' or whatever. Not 5:00 or something.

    In all honesty though, I suggest you use a NumericUpDown control instead of a text box to avoid any mistaken user input.
    Last edited by Apoc; 03-03-2009 at 04:30 PM. Reason: Can't type for shit today.

  8. #8
    Clain's Avatar Banned
    Reputation
    179
    Join Date
    Jan 2008
    Posts
    1,396
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    EDIT: Apawk got me

  9. #9
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks alot Apoc, should i use this instead of the Timespan thing? .-)

  10. #10
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Krillere View Post
    Thanks alot Apoc, should i use this instead of the Timespan thing? .-)
    In your case, yes.

    The TimeSpan overload is really only useful if you're doing long processes that are made to run for a looooooooooooooong time. (Usually over 10 minutes or so)

    Eg; I use the TimeSpan overload when working with wakeup timers and whatnot in certain services. (Sleep a background thread for 2-4 hours, to wake up, sent off a notification to other services, and go back to sleep)

  11. #11
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. I got another crappy nab question. In AutoIt this is called WinActivate, in VB, AppActivate, whats it called in C#? I need to activate Wow, i read some stuff about SetForeGround, but it requires alot of preperations and i want to know what im writing now just write it, so im not gonna do that. I also read some stuff about making a VB Reference. I dont know anything about it really, but the VB reference thing seems like something i might use. But can anyone can tell me the best way to AppActivate / WinActivate in C#? :-)

  12. #12
    Jens's Avatar Contributor
    Reputation
    179
    Join Date
    Sep 2006
    Posts
    251
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just wrote this out of memory, but it should work
    Code:
     DllImport("user32.dll")]
    publicstaticexternbool SetForegroundWindow(IntPtr hWnd);
    
    System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("Wow");
     if (p.Length > 0)
    { 
        SetForegroundWindow(p[0].MainWindowHandle);
    }
    
    
     

  13. #13
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. I copy pasted what you wrote in my program, and i got 13 errors, just gonna try to fix it.

    Edit. 5 errors left! Just gonna post the picture because i dont know what to do :S


    Last edited by Krillere; 03-04-2009 at 03:22 PM.

  14. #14
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PInvokes (DllImports) are considered methods. So they need to be within class scope. Not member/method scope. (Just put it outside of your Whisper_Tick method.

    Code:
        DllImport("user32.dll")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
    
        private void Whisper_Tick(object sender, EventArgs e)
        {
            System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("Wow");
            if (p.Length > 0)
            { 
                SetForegroundWindow(p[0].MainWindowHandle);
                // Do your other stuff in here.
            }
        }

  15. #15
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    using System.Runtime.InteropServices;
    Code:
    [DllImport("user32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);
    Code:
    SetForegroundWindow(Process.GetProcessesByName("wow")[0].Handle);
    Assuming it's for activating WoW.exe, ofc.
    Last edited by MaiN; 03-04-2009 at 03:55 PM.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

Page 1 of 2 12 LastLast

Similar Threads

  1. Hello, can't bump my thread. need help
    By cryptonitex in forum Report Bugs
    Replies: 3
    Last Post: 07-08-2013, 08:06 AM
  2. Sleep helping program? Monitor Tinting
    By Parog in forum Community Chat
    Replies: 6
    Last Post: 04-15-2010, 02:10 AM
  3. Won't Mysql start? Check this thread for help!
    By Tompilot in forum WoW EMU Guides & Tutorials
    Replies: 9
    Last Post: 12-31-2008, 01:07 PM
All times are GMT -5. The time now is 01:35 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search