Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically, a timer just sits there and counts, and every X milliseconds it "ticks"; it raises an event, which you can subscribe to with a method that does whatever you want done every X milliseconds.</p> <p>First, all of the variables you will need inside the loop, that come from outside the loop, will need to have "instance scope"; they must be a part of the object that currently has this method, and not "local" variables like they are now.</p> <p>Then, your current method will need to perform all of the steps prior to the while loop, setting whose "instance" variables I mentioned, and then create and start a Timer. There are several Timers in .NET; the two that would be most useful would likely be either the System.Windows.Forms.Timer or the System.Threading.Timer. This timer will need to be given a handle to the method it should call when it "ticks", and should be told how often to "tick".</p> <p>Finally, all the code inside the while loop, EXCEPT the calls to Application.DoEvents() and Thread.Sleep(), should be placed in the method that the Timer will run when it "ticks".</p> <p>Something like this ought to work:</p> <pre><code>private string[] join; private int number; private int start; private Timer lyricsTimer; private void StartShowingLyrics() { string lyricspath = @"c:\lyrics.txt"; TextReader reader = new StreamReader(lyricspath); start = 0; string[] read = File.ReadAllLines(lyricspath); join = String.Join(" ", read); number = join.Length; lyricsTimer = new System.Windows.Forms.Timer(); lyricsTimer.Tick += ShowSingleLine; lyricsTimer.Interval = 300; lyricsTimer.Enabled = true; } private void ShowSingleLine(object sender, EventArgs args) { start++; string str = join.Substring(start, 15); byte[] bytes = Encoding.BigEndianUnicode.GetBytes(str); label9.Text = str; if (start == number - 15) { start = 0; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload