Skip to main content

Posts

Showing posts from March, 2011

ODP.Net issue for 10.2.0.4 driver

Please note that Windows 7 has a new Oracle Client (10.2.0.4). In most cases this should be simply the case of removing the existing reference to Oracle.DataAccess from your application and adding a new one from new client folder. However in one case, we came across rather an unusal problem. We call stored functions from a windows application which return Integer type value. Please note we are using RETURN type values not OUT type parameters as this a Function. Here is the C# code. /****************************/ OracleCommand cmd = new OracleCommand("DoesDataItemExist", oraCn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("RETURN_VALUE", OracleDbType.Int16, ParameterDirection.ReturnValue); cmd.Parameters.Add("p_ID", id); cmd.Parameters.Add("p_YEAR", year); oraCn.Open(); cmd.ExecuteNonQuery(); Int16 retVal = (Int16)cmd.Parameters["RETURN_VALUE"].Value; oraCn.Close(); return retVal > 0

How to pass and Reterive data from Thread - Part 3

To reterive data from a Thread, you need a delegate callback methdo. step1 : Decalre the delegate for the callback method public delegate void CallbackMethod(int anynum); This delegare define the signature of the funtion which will be called by the Thread. Step 2: Amend you call to accept delegate method while creating instance of the class private CallbackMethod _callback; public TypeSafe(int num, string msg, CallbackMethod callback) { _num = num; _msg = msg; _callback = callback; } Step 3: Amend the ThreadProc (procedure that will be running on the Thread) to make a call to callback method public void ThreadProc() { Console.WriteLine(_msg, _num); if (_callback != null) { _callback(_num + 100); } } Step 4: Create a static function which you want to be called by the Thread. Note this should match the signature of the delegate public static void ResultCallback(int n) { Console.WriteLine("result from callback is {0}", n); } Step 5: P

How to pass data to Thread - Part 2

Passing data to Thread using ParameterizedThreadStart  is the easiest way but not a type safe way as Thead.Start accepts any object. Alternative way is to encapsulate Thread procedure and data in a helper class and use the ThreadStart delegate to execute the Thread procedure. Make a note that you cannot return data from the Thread as there is no way to retrieve data from an asynchronous call. To retrieve data, you need callback method....which will look at part 3 of this article. Here is an example on how to pass data in a type safe way using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace ThreadTypeSafe { class Program { static void Main(string[] args) { TypeSafe ts = new TypeSafe(100, "This is message from a TypeSafe Thread with num as {0}"); Thread t1 = new Thread(ts.ThreadProc); t1.Start(); t1.Join();

How to pass parameter to a Thread?

When a managed thread is created, the method that executes on the thread is represented by a ThreadStart or ParameterizedThreadStart delegate that is passed to Thread constructor For E.g. //to call a method with no parameters, use ThreadStart Thread t1 = new Thread(new ThreadStart(MyMethod)); //to call a method with parametets, use ParameterizedThreadStart Thread t1 = new Thread(new ParameterizedThreadStart(MyMethod)); To make it easy, Visual Basic and C# allow a short cut //short cut method Thread t1 = new Thread(MyMethod); Now the compiler works out which delegate constructor to use based on definition of MyMethod. To pass a parameter, similpy pass a value when you call Start on the Thread t1.Start(14); ///will pass 14 to MyMethod t1.Start("my message"); ///wiil pass "my message" to MyMethod //definition of MyMethod public static void MyMethod(object data) { //cast data to correct type and use data value //for e.g. output as string Co