|
|
I usually create a bridge written in C++ managed which creates one managed class and namespace that could be later imported into C#, but underneath this managed C++ class works with that actual and normal C++ class any way it is expected to work with this class, either I compile them together or I import dll and call this class internally.
This bridge serves several good purposes: to test what actually I need in C# from that C++ class. Only those things pass the bridge. Second the bridge is an excellent place to check if parameters are passed correctly and if some of them have to be arranged differently: pointers, arrays... all need different treatment in C# and C++.
If you don't have this bridge, but you directly call a C++ procedure from C# then you have to think about this inside C# code every time you call a specific C++ function. And then if you want to use the same C++ class again, the same problem. With bridge you just import it and everything is tested.
|
|
|
|
|
Hi all,
How can i find out process path?
i am using following code for getting process file name. i need to get the path of that file also. Can any one help me??
Process[] arrProcesses = Process.GetProcesses();
for (int i = 0; i <= arrProcesses.Length - 1; i++)
{
Process objProcess = arrProcesses[i];
if (objProcess.ProcessName == "WINWORD" && !(objProcess.MainWindowHandle == IntPtr.Zero))
{
string FileNameDefault = objProcess.MainWindowTitle;
string[] str1;
str1 = FileNameDefault.Split('-');
// System.IO.Path pt=objProcess.exe
FileNameDefault = str1[0];
}
}
Regards
Lijo
|
|
|
|
|
objProcess.MainModule.FileName
Edit: Suggestion: If you are searching for only Winword processes you can use Process.GetProcessesByName to avoid the loop and checking for the particular process name
modified on Monday, March 2, 2009 9:46 AM
|
|
|
|
|
ABitSmart wrote: avoid the loop
GetProcessesByName() returns an array, just like GetProcesses() does; it probably will be a shorter array, but you may still want to enumerate it.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:58 AM
|
|
|
|
|
My intention was to make the OP aware about GetProcessesByName. Thanks for your comment
(edited my comment)
|
|
|
|
|
Hi,
I have using sockets to communicating with our client applications. In the server application Listener i mentioned backlog 200 but most of the times the connection queue holds below 100 requests only. In this case some times when client try to connect .Net throw an error which says the queue was full. After that Listener will not take any new connections and it just close socket immediatly.
ListenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, 4098);
ListenSocket.Bind(ipLocal);
ListenSocket.Listen(200);
ListenSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
Error: [OnClientConnect]->
An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full
I dont understand what is happening there............
Please give me the solution....
friendly,
ranandbe
|
|
|
|
|
Hi All,
I need to insert a char in the beginning of the XML file. Char is “?”.
Tried with binary writer but it inserted few extra characters also.
Has anybody faced similar issue?
Or is there any other way to do it ?
Thanks & Regards,
Maan
|
|
|
|
|
Member 578189 wrote: I need to insert a char in the beginning of the XML file. Char is “?”.
If you insert ? to the beginning of XML file, XML file will become invalid and you will not be able to parse it. Are you trying to add the <?xml version="1.0" encoding="utf-8" ?> line?
|
|
|
|
|
Navaneeth,
my original line is
and i need ?<xml version="1.0" encoding="utf-8">;
small background about what i am doing:
I am creating a xml file in console and trying it save it as XML.
And when i use this XML it gives me an error because char "?" is missing.
|
|
|
|
|
Member 578189 wrote: I am creating a xml file in console and trying it save it as XML.
Use the XML manupulation classes like XMLDocument . It has got a Save method which writes a XML file.
|
|
|
|
|
Dear All,
i am using DataRow for insert update query for records in c# and this error below what should i do?
Update requires a valid Insert Command when passed DataRow collection with new rows
what i have to do for insert record ?
Is this is good approach to insert and update data in tables.
Kindly brief me.
Sajjad Lashari
|
|
|
|
|
Sajjad Leo wrote: what i have to do for insert record ?
Follow the instructions in the error message. You need to create an Insert command on the SqlDataAdapter.
Sajjad Leo wrote: Is this is good approach to insert and update data in tables.
In my opinion? No, never.
|
|
|
|
|
Hi Dear,
You replayed good but i am still not able to get my goal,
can you guide me if i am inserting a record what steps should i follow please send me complete steps.
Sajjad
|
|
|
|
|
Sajjad Leo wrote: please send me complete steps
You have not sent me complete detail of what you are wanting inserted and where.
Basically, create a SqlConnection object, create a SqlCommand object, Open the connection, ExecuteNonQuery on the command object and then Close the connection.
Your command should preferably use stored procedures in the database.
|
|
|
|
|
Dear,
I solved that problem now i using a sql query for retrieving a record from a student table i am selecting class from drop down like Class A and then the data of class A name of students will display in list box and then i select one name of class A from list box and want to display data in grid view i am writing query like
string rec = "select * from student_biodata where student_name = '" + liststudent.Text + "' ";
But one problem is that if i am selecting name like 'a' then two record displayed in grid view like 'a' of class A and 'a' of Class B so what should i do please guide me correct query as i can get only one record.
Thanks
Sajjad Ali
modified on Tuesday, March 3, 2009 5:22 AM
|
|
|
|
|
What is the best method if I want to limit The number of connections a server accepts?
I suppose this is not really a good way to achieve what i want:
while(true)
{
if(numberOfConnections < 100)
{
Socket s = listenerSocket.Accept();
...
}
else
{
Thread.sleep(1);
}
}
Has anyone a better idea how to keep the cpu down?
|
|
|
|
|
I's probably use a ManualResetEvent instead of sleeping a thousand times per second - it's more accurate and less of a hack.
ManualResetEvent m = new ManualResetEvent(true);
while(true)
{
m.WaitOne();
if(numberOfConnections < 100)
{
Socket s = listenerSocket.Accept();
...
}
else
{
m.Reset();
}
}
And somewhere at a place where you close the connections, do m.Set() if the number of connections is lower than 100 again.
But beware, I just woke up, so don't trust this code or even this idea
|
|
|
|
|
Hi Harold,
harold aptroot wrote: sleeping a thousand times per second
you are an optimist then. You may be interested in my article on timers.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:59 AM
|
|
|
|
|
Lol yea I exaggerated - how about: Up to a thousand times per second but it will never be that much due to the bad timer resolution.
But the idea is the same.. sleeping "many" times per second isn't a good idea.
|
|
|
|
|
Hmm I think I'll have to be carefull with the m.Set()
but worth trying...
|
|
|
|
|
Use the asynchronous fashioned methods. Like BeginXXX() and EndXXX(). There is a Socket.BeginAccept[^] available.
|
|
|
|
|
I don't understand how that would spare the cpu
or would help me to get rid of Sleep(x) ;?
I just want my loop to block, so it won't accept any new connections
until the older ones are gone... without using any cpu time.
|
|
|
|
|
See MSDN[^] got a sample.
|
|
|
|
|
Hi,
invader82 wrote: Has anyone a better idea how to keep the cpu down?
Use an event-driven scheme if one is available: getting a signal something must be done, is more efficient than having a loop polling whether somethind should be done all the time. (BTW: Thread.Sleep(1) will take 10 or more msec on average, see my timers article).
If you can't use an event-driven scheme (because no event is available, or you don't trust it sufficiently), implement a polling loop, however give it a delay that fits with your needs, e.g. if the client is a human typing/clicking in a browser, 50 msec would be good enough.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:59 AM
|
|
|
|