Help with Threads Please

GoncaloLopesGoncaloLopes goncalo lopesPTMember ✭✭

Thread recording;

some method{
if (!state) {
state = true;
recording = new Thread(GetStream(aux)); !!!! error cannot copnvert from void to System.action
recording.Start();
}
else
{
state = false;
}
}

private void GetStream(string aux)
{
string now = DateTime.Now.ToString();
now = now.Replace(':', '-');
fs = new FileStream(now + ".mp3", FileMode.Create);
try
{
response = WebRequest.Create(aux).GetResponse();
}
catch (System.Exception ex)
{
System.Console.WriteLine("Unable to get web response: " + ex);
}
using (System.IO.Stream stream = response.GetResponseStream())
{
byte[] buffer = new byte[65536];
int read;
while ((state == true) && ((read = stream.Read(buffer, 0, buffer.Length)) > 0))
{
long pos = fs.Position;
fs.Position = fs.Length;
fs.Write(buffer, 0, read);
fs.Position = pos;
}
fs.Flush();
}
response.Close();
fs.Close();

    }

i dont know how to run this method qith a new thread

Best Answer

Answers

Sign In or Register to comment.