|
Thank you very much Robert for your quick response.
It seems I could not present my case properly. Here I am trying again.
I have a main application with MDI form with common menu items.
The modules will be available to a user depending upon from which department s/he is from. For example we will have a table to store the user and what module is available to that user
UserID
Module
And another table which contains the module name, and the menu text, that will be shown on the menu and corresponding DLL file name for that module.
Module
Menu Name
DLLFile
These DLL files will have a common method called show(). On the click event of the menu item, the show method basically will load the MDI Child form from the DLL and pass the MDI form reference of the main application as the parent form. With this the menu items on the child form will appear on the main menu of the MDI window.
Hope I made it clear this time.
Thanking you in for your kind help.
|
|
|
|
|
First you would have your parent form:
public class Daddy : Windows.Forms.Form {}
Now that form owns the menu and thus would handle the event for each menu selection. So then your event handler would be something like this: (WARNING: My machine with VS died last night so I'm tinkering with a very bad memory to write this!!!)
// using menuitem.Text append namespace and load it as object child.
MenuItem item = (MenuItem) sender;
// I am not sure of the method below or format but generally....
Assembly assembly = Assembly.LoadFile(path+item.Name);
IBaseChild child = (IBaseChild)assembly.LoadFile( nameSpace + item.Value );
child.MDIParent = this;
child.Show();
-- modified at 17:25 Tuesday 18th April, 2006
|
|
|
|
|
I didn't understand your requirement fully, but assuming that you're trying to load menu,froms and assmblies dynamically (all are unknown to you), can be be done this way:
<br />
public void invokeProcess (string assemblyName, string strModName) <br />
{<br />
Assembly assembly = Assembly.LoadFrom (assemblyName);<br />
<br />
foreach (Type type in assembly.GetTypes ()) <br />
{<br />
if (type.IsClass == true) <br />
{<br />
if (type.FullName != strModName + "." + strModClass) <br />
{<br />
continue;<br />
}<br />
<br />
object ibaseObject = Activator.CreateInstance (type);<br />
<br />
frmDummy frmParent = new frmDummy();<br />
frmParent.MdiParent = this;<br />
<br />
object[] arguments = new object [] {frmParent};<br />
<br />
foreach (MemberInfo mi in type.GetMember(strModEntry))<br />
{<br />
type.InvokeMember (mi.Name.ToString(), <br />
BindingFlags.Default | BindingFlags.InvokeMethod,<br />
null,<br />
ibaseObject,<br />
arguments);<br />
}<br />
}<br />
}<br />
}
hope this will help.
|
|
|
|
|
Thank you vatzcar for your time and kind help . After going through your code, I changed my strategy. Previously I was planning a show method in a class file (in DLL) will take the reference of the MDI form, after that it will show the menu form, in the DLL as child form. Now I am planning to standardise the main form name as frmMenu in all the DLL files. With this the code will be moved to the click event of the menu in the main application. The click event of the menu will call LoadDLL with corresponding assembly name.
private void LoadDLL(string assemblyName)
{
Assembly assembly = Assembly.LoadFrom (assemblyName);
foreach (Type type in assembly.GetTypes ())
{
if (type.IsClass == true)
{
object ibaseObject = null ;
if (type.Name == "frmMenu")
{
ibaseObject = Activator.CreateInstance(type);
Form frmT = (Form)ibaseObject;
frmT.MdiParent = this;
frmT.Show();
}
}
}
}
It is working fine . Is it optimized code?
Thank you.
|
|
|
|
|
I'm glad that somehow i could help you I think it's optimized. And don't thank me, it's the Dev community who deserve 'cause this is what they tought me through the time
|
|
|
|
|
Hi,
I need to call a webservice which needs to use a pool of database connections to read and write data in the DB. But a traditional webservice will create and destroy the connections as it is called and disguarded, but this will mean new connections to the DB all the time.
This has a big hit on performance.
Therefore I need some way of maintainig a pool of connections which is constantly open and available to all instances of the webservice to use(at least one per database) to ensure performance. But how can this be done?
I have done some tests using global.asax, but this does not work.
I also can not find anything on the web.
Can anybody help?
regards
Jason
|
|
|
|
|
Hi,
I need to call a webservice which needs to use a pool of database connections to read and write data in the DB. But a traditional webservice will create and destroy the connections as it is called and disguarded, but this will mean new connections to the DB all the time.
This has a big hit on performance.
Therefore I need some way of maintainig a pool of connections which is constantly open and available to all instances of the webservice to use(at least one per database) to ensure performance. But how can this be done?
I have done some tests using global.asax, but this does not work.
I also can not find anything on the web.
Can anybody help?
regards
Jaso
|
|
|
|
|
Hi,
I need to call a webservice which needs to use a pool of database connections to read and write data in the DB. But a traditional webservice will create and destroy the connections as it is called and disguarded, but this will mean new connections to the DB all the time.
This has a big hit on performance.
Therefore I need some way of maintainig a pool of connections which is constantly open and available to all instances of the webservice to use(at least one per database) to ensure performance. But how can this be done?
I have done some tests using global.asax, but this does not work.
I also can not find anything on the web.
Can anybody help?
regards
Jaso
|
|
|
|
|
Why flood the board with 3 of the same question? If you thought your message didnt post did it occur to you to CHECK before reposting (or hitting submit again and again)
Connections to databases like MSSQLServer are pooled by the provider, trying to re-invent connection pooling will lead to WORSE performance, I promise!
-- modified at 11:08 Tuesday 18th April, 2006
|
|
|
|
|
Hi,
Two things;
1. I did check and it did not appear, plus I got a strange error message
2. I am not trying to reinvest connection pooling, look at the question in detail.
If you call a webservice then it will initiate a new instance, including a new instance of the pooling because there is nothing already in memory and therefore nothing to use. Therefore there is no benefit to pooling in this case.
I want to share database connections between istances of the webservice, not within the websevice itself.
Jason
|
|
|
|
|
Ok, I wasn't sure what board to put this so I am shooting here first as it is a c# code question:
I have the following XML Data that is returned from a 3rd party API. The resulting data is stored as a string and loaded into the XML dom as follows:
// s_invoices contains the XML
string s_invoices;
XmlDocument doc = new XmlDocument();
doc.InnerXml = s_invoices;
XmlElement root = doc.DocumentElement;
The XML itself looks like the following (sample):
<?xml version="1.0" encoding="UTF-8"?>
<Order_Invoice_Outgoing_Array_Element>
<Order_Invoice_Outgoing_Element>
<interface_transaction>18399</interface_transaction>
<transaction>18399</transaction>
<order_Invoice_Header>
<vendor>P00621</vendor>
<invoice>90951282</invoice>
<currency>USD</currency>
<invoice_Category>ORDER</invoice_Category>
<invoice_Date>2003-08-18T00:00:00.000-04:00</invoice_Date>
<invoice_Due_Date>2003-0818T00:00:00.00004:00</invoice_Due_Date>
<terms>NET30</terms>
<invoice_Amount_Total>6260</invoice_Amount_Total>
<status>CLOSED</status>
<currency_Exchange_Rate>1</currency_Exchange_Rate>
<order_Type_Optional>PO</order_Type_Optional>
<order_Number_Optional>40845</order_Number_Optional>
<pay_Indicator>AP</pay_Indicator>
<original_Invoice_Amount>0</original_Invoice_Amount>
<GL_Account>
<GL_Company>443120</GL_Company>
<GL_Expenditure>809</GL_Expenditure>
<GL>0</GL>
<GL_Cost_Center>0</GL_Cost_Center>
<GL_Description>REPAIR ORDERS</GL_Description>
<GL_Category>ALL</GL_Category>
<modified_By>GLACCOUNT</modified_By>
</GL_Account>
<voucher>78086</voucher>
<created_By>TGREEN</created_By>
<created_Date>2003-10-31T00:00:00.000-05:00</created_Date>
<modified_By>PFAPHSTN</modified_By>
<modified_Date>2006-03-19T00:00:00.000-05:00</modified_Date>
<line_Sum>6260</line_Sum>
<AP_System_Received_Flag>false</AP_System_Received_Flag>
<paid_Flag>true</paid_Flag>
<interface_Batch>14975</interface_Batch>
</order_Invoice_Header>
<order_Invoice_Lines>
<order_Invoice_Line>
<order_Type>PO</order_Type>
<order_Line>7</order_Line>
<order_Number>40845</order_Number>
<invoice_Category>ORDER</invoice_Category>
<invoice_Date>2003-08-18T00:00:00.000-04:00</invoice_Date>
<invoice_Amount>6260</invoice_Amount>
<invoiced_Qty>1</invoiced_Qty>
<GL_Account>
<GL_Company>443120</GL_Company>
<GL_Expenditure>809</GL_Expenditure>
<GL>0</GL>
<GL_Cost_Center>0</GL_Cost_Center>
<GL_Description>REPAIR ORDERS</GL_Description>
<GL_Category>ALL</GL_Category>
<modified_By>GLACCOUNT</modified_By>
</GL_Account>
<status>CLOSED</status>
<assigned_To>VHAINES</assigned_To>
<credit_Memo>78086</credit_Memo>
<credit_Memo_Cost>0</credit_Memo_Cost>
<original_Invoice_Amount>0</original_Invoice_Amount>
<created_By>TGREEN</created_By>
<created_Date>2003-10-31T00:00:00.000-05:00</created_Date>
<modified_By>PFAPHSHD</modified_By>
<modified_Date>2006-03-19T08:39:39.000-05:00</modified_Date>
<line_Amount>6260</line_Amount>
</order_Invoice_Line>
</order_Invoice_Lines>
</Order_Invoice_Outgoing_Element>
</Order_Invoice_Outgoing_Array_Element>
So basically it is a very convoluted XML string. Now what I want to do is populate the XML into a form but am having problems finding what I am looking for.
I am currently using the following:
Console.WriteLine(" The terface_transaction : {0}", root.GetAttribute("//Order_Invoice_Outgoing_Array_Element/Order_Invoice_Outgoing_Element/interface_transaction"));
To try to write out just the interface transaction portion of the XML but alas it is not working. I am thinking it is because maybe GetAttribute is set to start at root and somehow my pathing is wrong, any ideas?
-- modified at 10:38 Tuesday 18th April, 2006
|
|
|
|
|
Hi,
hard to read that XML stuff without proper formmating but I think the caus is that interface_transaction isn't an attribute - it's a node. Although I don't know the error message (you should have specified it instead of 'not wokring') I assume it should be something like:
root.SelectSingleNode("Order_Invoice_Outgoing_Array_Element/"
+ "Order_Invoice_Outgoing_Element/interface_transaction").Value
This should give you the text. You could also split the query to further verify where the problem lies:
XmlNode firstNode = root.SelectSingleNode("Order_Invoice_Outgoing_Array_Element");
XmlNode secondNode = firstNode.SelectSingleNode("Order_Invoice_Outgoing_Element");
XmlNode thirdNode = secondNode.SelectSingleNode("interface_transaction");
Console.WriteLine(thirdNode.Value);
This way you could step through with the debugger and identify where exactly something is not found.
|
|
|
|
|
One approach you could investigate is as follows:
If the xml is well-formed, and the xml can be defined by a schema, and you have enough time to quickly code a class and a test program, then do this:
The xml that is passed to you would be passed into a stream (search for putting a string to a stream for implementation details)
next create a class that represents the data (you may have to work backwards....create the class, serialize it, then see if it matches the xml)
Next take the stream and feed it into an XmlSerializer to turn it into a C# object. From that point forward you are working with an object instead of screwing around with the DOM.
-- modified at 16:21 Tuesday 18th April, 2006
|
|
|
|
|
:(Newbie to c#:
I was working on an example given from a book and I totally got confused.
Please correct me.
I was under the impression that in c# the default way of passing arrays (like any other element) is "byval".
If we don't mention any thing when passing an array to a method, what is the default way?
like
int[] firstarray = {32,33,34};
firstdouble(firstarray);
what is the difference between this way versus this way?
int[] secondarray = {22,23,22};
seconddouble(ref secondarray);
thanks
nath
bnath
|
|
|
|
|
The default is to pass by value. If you want reference semantics, you can use the ref keyword.
Typically, the ref keyword (similar to the out keyword) is only used with value types (i.e. integer, double, float, etc.) For example:
int i = 5;
Test(i);
Debug.WriteLine(i);
void Test(int param)
{
param = 10;
}
string str = "hello";
Test(str);
Debug.WriteLine(str);
void Test(string param)
{
param = "world";
}
int i = 5;
Test(ref i);
Debug.WriteLine(ref i);
void Test(ref int param)
{
param = 10;
}
string str = "hello";
Test(ref str);
Debug.WriteLine(str);
void Test(ref string param)
{
param = "world";
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: I luv teh choco
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
As you are a beginner just some more infos which might have caused your confusion:
Not having the ref keyword doesn't mean changes to the array aren't affecting the caller. It just means that changing the reference of the parameter doesn't has any effect. If you change the contents of the array the caller will still notice it.
public void DoSomething(int[] values)
{
values = new int[] { 1, 2, 3 };
}
public void DoSomething(int[] values)
{
values[0] = 1;
values[1] = 2;
values[2] = 3;
}
public void DoSomething(ref int[] values)
{
values = new int[] { 1, 2, 3 };
}
|
|
|
|
|
Default is passing by value, but for reference types it means that you pass the value of the reference, e.g. the reference is copied, but the object that it refers to is not.
A reference is basically a pointer to the address where the actual data is stored, so when you pass the array to the method it's just a 32-bit pointer value that is really passed to it. The array itself is never copied.
In both your examples the method you call can alter the contents of the array, but in the second example it can also change the value of the reference, e.g. the secondarray variable.
---
b { font-weight: normal; }
|
|
|
|
|
Please show your ability helping the following program
I use 2 threads, 1 read character from keyboard, 1 output 1 character at a time to console.
How can I pass values from Thread 1 to Thread 2? (I use boolean values but It doesnot work because Thread 2 takes only 1 object parameter)
Is there any other way of doing it?
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Threading;<br />
<br />
namespace SS<br />
{<br />
class Program<br />
{<br />
static string m1 = "\nType a string of text then press Enter. " +<br />
"Type '+' anywhere in the text to quit:\n";<br />
static string m2 = "Character '{0}'";<br />
static string m3 = "Character ";<br />
static char ch;<br />
static int x;<br />
<br />
static bool isM1 = false;<br />
static bool isM2 = false;<br />
static bool isM3 = false;<br />
<br />
static void Main(string[] args)<br />
{ <br />
Console.WriteLine(m1);<br />
<br />
<br />
Thread t1 = new Thread(new ParameterizedThreadStart(Program.ReadInput));<br />
Thread t2 = new Thread(new ParameterizedThreadStart(Program.ReadOutput));<br />
<br />
Console.WriteLine("Thread 1 starting...");<br />
t1.Start(x);<br />
Console.WriteLine("Thread 2 starting...");<br />
t2.Start(x);<br />
<br />
Thread.Sleep(80 * 1000);<br />
}<br />
<br />
public static void ReadInput(object param)<br />
{ <br />
int input = (int)param; <br />
<br />
do<br />
{<br />
input = Console.Read();<br />
<br />
try<br />
{<br />
ch = Convert.ToChar(input);<br />
if (Char.IsWhiteSpace(ch))<br />
{<br />
isM3 = true;<br />
if (ch == 0x0a)<br />
isM1 = true;<br />
}<br />
else<br />
isM2 = true;<br />
}<br />
catch (OverflowException e)<br />
{<br />
Console.WriteLine("{0} Value read = {1}.", e.Message, input);<br />
ch = Char.MinValue;<br />
Console.WriteLine(m1);<br />
}<br />
} while (ch != '+');<br />
<br />
x = input;<br />
}<br />
<br />
public static void ReadOutput(object param1)<br />
{<br />
int output = (int)param1;<br />
<br />
if (isM3)<br />
{<br />
Console.WriteLine(m3, output);<br />
}<br />
<br />
if (isM1)<br />
{<br />
Console.WriteLine(m1);<br />
}<br />
<br />
if (isM2)<br />
{<br />
Console.WriteLine(m2, ch, output);<br />
}<br />
<br />
}<br />
}<br />
}<br />
eric
|
|
|
|
|
You can pass a boolean as the object parameter to the thread. You can then cast the object back to boolean when the other thread receives it.
|
|
|
|
|
I'm not directly getting what you are trying to achieve but if the only problem is that you can pass only one parameter to your thread function you could just pack more info into that one object parameter:
public void StartMyThread()
{
int param1 = 0;
bool param2 = false;
string param3 = "Hello World!";
t2.Start(new object[] { param1, param2, param3 } );
}
public static void MyThreadFunction(object paramAll)
{
object[] paramArray = (object[])paramAll;
int param1 = (int)paramArray[0];
int param2 = (bool)paramArray[1];
int param3 = (string)paramArray[2];
}
This works because an object array is also an objectand thus you can stuff as many parameters as you want into the call.
A bit more typesafe variant would be:
public struct ThreadFuncParameters
{
public int Param1;
public bool Param2;
public string Param3;
}
public void StartMyThread()
{
ThreadFuncParameters params = new ThreadFuncParameters();
params.Param1 = 0;
params.Param2 = false;
params.Param3 = "Hello World!";
t2.Start(params);
}
public static void MyThreadFunction(object paramAll)
{
ThreadFuncParameters params = (ThreadFuncParameters)paramAll;
int param1 = params.Param1;
int param2 = params.Param2;
int param3 = params.Param3;
}
I would prefer that way because you wouldn't cast so often as in the first example and casts are always a source for runtime exceptions.
|
|
|
|
|
Thanks so much Robert
I'm doing now
eric
|
|
|
|
|
I've got a problem.
How can I pass variables from ReadInput function to ReadOutput function via struct?
Please help.
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace ConsoleApplication9
{
class Program
{
static string m1 = "\nType a string of text then press Enter. " +
"Type '+' anywhere in the text to quit:\n";
static string m2 = "Character '{0}'";
static string m3 = "Character ";
public struct ThreadFuncParameters
{
public static char ch;
public static int x;
public static bool isM1 ;
public static bool isM2 ;
public static bool isM3 ;
}
static void Main(string[] args)
{
Console.WriteLine(m1);
ThreadFuncParameters pas = new ThreadFuncParameters();
pas.ch = 'a' ;
pas.x = 0;
pas.isM1 = false;
pas.isM2 = false;
pas.isM3 = false;
Thread t1 = new Thread(new ParameterizedThreadStart(Program.ReadInput));
Thread t2 = new Thread(new ParameterizedThreadStart(Program.ReadOutput));
Console.WriteLine("Thread 1 starting...");
t1.Start(pas);
Console.WriteLine("Thread 2 starting...");
t2.Start(pas);
}
public static void ReadInput(object paramALL)
{
ThreadFuncParameters par = (ThreadFuncParameters)paramALL;
char p1 = par.ch;
int p2 = par.x;
bool p3 = par.isM1;
bool p4 = par.isM2;
bool p5 = par.isM3;
do
{
p2 = Console.Read();
try
{
p1 = Convert.ToChar(p2);
if (Char.IsWhiteSpace(p1))
{
p5 = true;
if (p1== 0x0a)
p3= true;
}
else
p4 = true;
}
catch (OverflowException e)
{
Console.WriteLine("{0} Value read = {1}.", e.Message, p2);
p1 = Char.MinValue;
Console.WriteLine(m1);
}
} while (p1!= '+');
ch = p1;
x = p2;
isM1 = p3;
isM2 = p4;
isM3 = p5;
}
public static void ReadOutput(object paramALL)
{
ThreadFuncParameters par = (ThreadFuncParameters)paramALL;
char p1 = par.ch;
int p2 = par.x;
bool p3 = par.isM1;
bool p4 = par.isM2;
bool p5 = par.isM3;
if (p5)
{
Console.WriteLine(m3, p2);
}
if (p3)
{
Console.WriteLine(m1);
}
if (p4)
{
Console.WriteLine(m2, p1, p2);
}
}
}
}
eric
|
|
|
|
|
How to pass parameters between threads greatly depends on what exactly you want to do. As far as I see you are starting both thread paralell where the ReadOutput thread just writes some lines to the console and ReadInput waits for user input. In this scenario ReadOutput will probably be finished before the user can input anything.
Please try to explain what you are actually trying to achieve with your code. Than I will try to give you a good way to achieve your goal.
|
|
|
|
|
Does anyone have experience creating an ebXML message in a soap envelope using a c# client application?
I have a windows app that needs to create, format, and post an ebXML message.
I've looked at a lot of sites (including ebxml.org) and EVERYTHING is java java java.
Any help would be greatly appreciated.
Paul Brower
|
|
|
|
|
hi all,
I have a treeview that I load from a dataset(baiscly files in a dir). I want to use the checkbox option in the treeview, when I uncheck a node it must be disabled. other app. can ask for the exsting nodes, I read this from the dataset not from the treeview.
beqause I load the treeview from a dataset I can not use the on_select method.
is there any way to put the treeview checkbox option in the dataset, and wacht if it change?
so that I can give the correct answer.
thanks
|
|
|
|