fire timer event

Tech-Archive recommends: Speed Up your PC by fixing your registry



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

*** Sent via Developersdex http://www.developersdex.com ***
.



Relevant Pages

  • Re: IDbTransaction spanning several methods
    ... In theory, however, a BLL call could span multiple DAL objects ... transaction state and pass such an object around across DAL calls. ... > public void CommitTransaction() ...
    (microsoft.public.dotnet.distributed_apps)
  • Re: IDbTransaction spanning several methods
    ... In theory, however, a BLL call could span multiple DAL objects ... transaction state and pass such an object around across DAL calls. ... > public void CommitTransaction() ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: IDbTransaction spanning several methods
    ... > public void MyMethod(...., ref IDbTransaction trans) ... I can swallow the transaction stuff in the BLL code, ...
    (microsoft.public.dotnet.framework.adonet)
  • Import of MSDTC transaction failed: Result Code = 0x8004d00e.
    ... ServiceConfig config = new ServiceConfig; ... public void TearDown() ... In case it is related I occasionally get the following error message: ... Distributed transaction completed. ...
    (microsoft.public.dotnet.framework.component_services)