fire timer event

B

BC

Hi all,

I have two classes: TransactionCollection and Transaction, where
TransactionCollection is used to store Transaction objects.

public class TransactionCollection : CollectionBase
{
public TransactionCollection()
{
}

public void Add(Transaction transaction)
{
List.Add(transaction);
}
}


public class Transaction
{
private int _transactionID;
private Timer _expireTime;

public Transaction()
{
_expireTime = new Timer();
}

public int TransactionID
{
set{ _transactionID = value; }
}

public void Start()
{
_expireTime.Interval = 3000;
_expireTime.Start();
_expireTime.Tick += new EventHandler(CancelTransaction);
}

private void CancelTransaction(object sender, EventArgs e)
{
Console.WriteLine("cancel transaction...);
}
}

Now in my main method (application start), I created a transaction
object with transaction ID and timer, then added it to the transaction
collection class:

TransactionCollection tc = new TransactionCollection();
Transaction t= new Transaction();
t.TransactionID = 1;
t.Start();
tc.Add(t);

Im expecting the transaction objects in the transaction collection class
will fire the timer event (CancelTransaction) respecting to it's
_expireTime.Interval (i.e. every second in this example).

However the transaction object event is never fired up. What did I
missed in the codes? What can I do to make sure the event fire?


Cheers,

Benny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top