need some help trying to pass a value from a timer event
this is my timer event and method being called Mywords ()
_ourwordLength; is an instance variable that is returned by a method
am calling getlength ie int getlength(int _ourwordLength ){ return _ourwordLength; }
private static int _ourwordLength;
public void Timer_tick(object sender, EventArgs e)
{
Mywords(_ourwordLength);
}
The method am passing value to is below
{
Mywords(_ourwordLength);
}
The method am passing value to is below
public void Mywords( int length)
{
var ResourceStream = Application.GetResourceStream(new Uri("TextFile1.txt", UriKind.Relative));
using (Stream Myfilestream = ResourceStream.Stream)
{
string s = "";
StreamReader myStreamReader = new StreamReader(Myfilestream);
s = myStreamReader.ReadToEnd();
// string regExp;
if (length == 5)
{
MywordsLength();
}
{
var ResourceStream = Application.GetResourceStream(new Uri("TextFile1.txt", UriKind.Relative));
using (Stream Myfilestream = ResourceStream.Stream)
{
string s = "";
StreamReader myStreamReader = new StreamReader(Myfilestream);
s = myStreamReader.ReadToEnd();
// string regExp;
if (length == 5)
{
MywordsLength();
}
The problem i have is once the value _ourwordLength is passed to the Timer event where am calling the mywords method its is not being passed to the
mywords method help on this plis
VulpesPosted Jan 28, 2014, 9:16 AM
If you want to set the private static field, _ourwordLength, from another class, I'd use this method instead:
public static void setlength(int value)
{
_ourwordLength = value;
}
solomon mwikaPosted Jan 28, 2014, 9:04 AM
VulpesPosted Jan 28, 2014, 8:44 AM
Initially, this will have a default value of 0 unless it's being set to a different value somewhere in the code before the Timer is started.
If _ourworldLength never changes between Tick events, then I'd take a look at the code which sets it (not shown in your snippet). You might be declaring a local variable with the same name and setting that instead which is an easy mistake to make.