Tody I read article on InokeRequired patterns posted in code project ( Read Full Article )
I have wrote more generic version of the same ( Less code !!!!! ...clear & crisp...)
public static class ControlExtension
{
public static void UpdateControl(this Control control, MethodInvoker code)
{
if (control.InvokeRequired) {
control.Invoke(code);
}
else{
code.Invoke();
}
}
using 'Control' type param in Extension mentod give us an advantage to call UpdateControl on any control.
for eg:- In the below example I have called 'UpdateControl' extension method on textbox control.
private void btnUpdate_Click(object sender, EventArgs e)
{
Thread th = new Thread(new ThreadStart( () => txtInfo.UpdateControl(Display) ) );
th.Start();
}
private void Display()
{
txtInfo.Text += "Updated";
}
Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts
Monday, 29 June 2009
Monday, 4 May 2009
Matlab Neural Network in C# Application
Part 1 gives an overview of Matlab Network manager . This screen cast shows how to create XOR network using Matlab Network Manager.
This part explains how to use Matlab Neural Network in c# windows application and limitation of Matlab complier with respect to 'sim' function.
Note:- Don't forget to watch next episode of this series, in which I have explained how to get around with 'sim' function compiler limitation and call Neural network from c# windows application
In this part I have explained how to get around with 'sim' function compiler limitation and call Neural network from c# windows application.
This part explains how to use Matlab Neural Network in c# windows application and limitation of Matlab complier with respect to 'sim' function.
Note:- Don't forget to watch next episode of this series, in which I have explained how to get around with 'sim' function compiler limitation and call Neural network from c# windows application
In this part I have explained how to get around with 'sim' function compiler limitation and call Neural network from c# windows application.
Monday, 2 March 2009
Developing Financial Applications using .Net & Matlab ( Part-1)
This video shows how we can use Algorithms written in matlab 'M' code can be used in .Net applications. (View the video in 'double size' resolution).
Matlab Code snippet
--------------------
function [ Price,AccruedInt ] = MyBndPrice(Yield, CouponRate, Settle,...
Maturity, Period, Basis)
[Price, AccruedInt] = bndprice(Yield, CouponRate, Settle,...
Maturity, Period, Basis);
end
.Net Code snippet
-------------------
private void btnBndPrice_Click(object sender, EventArgs e)
{
MWNumericArray yields = GetYields();
MWNumericArray coupon = new MWNumericArray(Convert.ToDouble(txtCoupon.Text) ) ;
MWNumericArray period = new MWNumericArray(cmbPeriod.SelectedIndex + 1 ) ;
MWNumericArray basis = new MWNumericArray(cmbBasis.SelectedIndex);
MWCharArray settlement = new MWCharArray(txtSettlement.Text);
MWCharArray maturity = new MWCharArray(txtMaturity.Text);
MyFinLib.MyFinLibclass finLib = new MyFinLib.MyFinLibclass();
MWArray[] result = finLib.MyBndPrice(2, yields, coupon, settlement, maturity, period, basis);
Display(result);
}
private double[] GetYields()
{
string[] yieldStr = txtYield.Text.Split(',');
double[] yields = new double[ yieldStr.Length ];
for (int i = 0; i < yieldStr.Length; i++)
yields[i] = Convert.ToDouble(yieldStr[i]);
return yields ;
}
private void Display(MWArray[] result)
{
DataTable dt = new DataTable();
dt.Columns.Add("Price");
dt.Columns.Add("Accrued Interest");
string[] price = result[0].ToString().Split('\n');
string[] accuredInt = result[1].ToString().Split('\n');
for (int i = 0; i < price.Length; i++)
{
DataRow row = dt.NewRow();
row[0] = price[i];
row[1] = accuredInt[i];
dt.Rows.Add(row);
}
dataGridView1.DataSource = dt;
}
Matlab Code snippet
--------------------
function [ Price,AccruedInt ] = MyBndPrice(Yield, CouponRate, Settle,...
Maturity, Period, Basis)
[Price, AccruedInt] = bndprice(Yield, CouponRate, Settle,...
Maturity, Period, Basis);
end
.Net Code snippet
-------------------
private void btnBndPrice_Click(object sender, EventArgs e)
{
MWNumericArray yields = GetYields();
MWNumericArray coupon = new MWNumericArray(Convert.ToDouble(txtCoupon.Text) ) ;
MWNumericArray period = new MWNumericArray(cmbPeriod.SelectedIndex + 1 ) ;
MWNumericArray basis = new MWNumericArray(cmbBasis.SelectedIndex);
MWCharArray settlement = new MWCharArray(txtSettlement.Text);
MWCharArray maturity = new MWCharArray(txtMaturity.Text);
MyFinLib.MyFinLibclass finLib = new MyFinLib.MyFinLibclass();
MWArray[] result = finLib.MyBndPrice(2, yields, coupon, settlement, maturity, period, basis);
Display(result);
}
private double[] GetYields()
{
string[] yieldStr = txtYield.Text.Split(',');
double[] yields = new double[ yieldStr.Length ];
for (int i = 0; i < yieldStr.Length; i++)
yields[i] = Convert.ToDouble(yieldStr[i]);
return yields ;
}
private void Display(MWArray[] result)
{
DataTable dt = new DataTable();
dt.Columns.Add("Price");
dt.Columns.Add("Accrued Interest");
string[] price = result[0].ToString().Split('\n');
string[] accuredInt = result[1].ToString().Split('\n');
for (int i = 0; i < price.Length; i++)
{
DataRow row = dt.NewRow();
row[0] = price[i];
row[1] = accuredInt[i];
dt.Rows.Add(row);
}
dataGridView1.DataSource = dt;
}
Subscribe to:
Posts (Atom)