|
Hello,
I have a little problem. Maybe someone here can help me.
The problem is: My program (written in C# .NET) calls a COM-Server. This Server works a little bit and then he sent me the Results back in a callback-method. This method is open by the COM-Server in a new Thread. So far so god.
After I became this results I have to sent the next command to the server. But before I can sent a new command, I have to release the complete callback-method from the COM-Server. But I can’t close this method before sending the new command.
At the moment I open a new Tread in this callback-method. This new Thread sent the new command after the old Thread closed. But sometimes the old Thread closed not so fast and then it crashes.
Is there a any standard way to solve this Problem?
Can someone help me?
Sorry for my English
David
|
|
|
|
|
What's the threading model of the COM server?
If you're objective is to send the next command back to the server in the first thread (the thread on which your proxy was instantiated), then you need to invoke a method on that thread. If you're calling methods on your proxy from a Windows Forms control or form, you can use Control.Invoke . The Framework handles calling the method on the thread on which the control was created if you call it right. For example:
delegate void SendCommandHandler(string command);
void SendCommand(string command)
{
}
void Callback()
{
if (InvokeRequired)
{
SendCommandHandler d = new SendCommandHandler(SendCommand);
Invoke(d, new object[] {"DO SOMETHING"});
}
else SendCommand("DO SOMETHING");
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
At first: Tanks for this Information,
The COM-Server is a STA Server but I can use only one Apartment at the same time, because the Server needs very mutch Performance.
So the problem is not to start a new Thread. (The invoke command is very nice) At the moment I sent the next command in a other Tread too, but it starts like this:
SentCommand wrapper=new SentCommand(Thread.CurrentThread,myobject);<br />
ThreadStart ts=new ThreadStart(wrapper.SentNewCommand);<br />
Thread SecondThread = new Thread(ts);<br />
SecondThread.Start();
The real Problem is the speed of the second Thread. When I start the second Thread from the Callback-Tread both Thread exist at the same Time. So if the Second Thread is too fast and sent the new command before the Callback-tread is closed -> it crashes. So I think its not important if the Second-Thread is a new one or a existing GUI-Tread (Control).
I tried to synchronise this 2 Treads like this:
if (CallbackThread != null) <br />
{<br />
if (CallbackThread.IsAlive)<br />
{<br />
CallbackThread.Abort();<br />
}<br />
}
but it doesn’t work.
|
|
|
|
|
What you're doing isn't synchronizing thread access - you need locks for that. The C# lock statement does just that. Define a static object initialized to an instance of something. In your case, you could also synchronize against this since your .NET component is running in an apartment.
The lock uses a Monitor . There's also Mutex and various events you can signal. I suggest you read through the documentation for the namespace members in System.Threading . There's a lot of ways you can correctly synchronize thread access.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Can somebody please give me some sample code
to play wav files through a TAPI interphase.
Thanx...
|
|
|
|
|
It's been said many times before in this forum (just Search first!), and as recently as yesterday, the TAPI 3.0 wrapper is heavily rumored to have problems, so you'll have to use a custom written TAPI 2.0 wrapper. You can find such an example here[^] on GotDotNet.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello,
I would like some help on the next problem I've encountered.
I want to know on my mainform if a child form was closed using the close-x of the window.
Microsoft says that you have the OnMdiChildActivate methode but this happens,
I quote "Occurs when a multiple document interface (MDI) child form is activated or closed within an MDI application."
Can anyone help?
|
|
|
|
|
Assuming the child has a reference to the mainform, then just give mainform a ChildClosed member, and put something like
parent.ChildClosed(this); in the close handler for the child form
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Sorry,
I'm just a beginner, so put something like... is a bit to non-specific for me.
Can you give a bit more details please.
Like what do you mean with a ChildClosed member?
|
|
|
|
|
"ChildClosed" was just a suggestion for a name - what I meant was in your MDI container class add a member function (call it whatever you like - ChildClosed seems to be a sensible name to me) that takes a parameter of whatever your child form type is
e.g.
public void ChildClosed( MyChildFormType ChildForm )
{
}
Now assuming your child window has some kind of parent property that's set when the child is first created, you can call the ChildClosed member from within the child's close window handler
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Sorry but I'm not quite where I want to be.
I will try to rephrase the problem. In my mainform I'vr got a menu for the 'windows'. You know the standard cascading en windowlist stuff.
I want to hide this menu just untill there are elements in the MdiList,
if(this.MdiChildren.Length > 0)
windowMenu.Visible = true;
Where do I put this check on the Mdichildren so I can be sure that when the Child is closed, but whatever method, the check is performed?
I've tried this:
void MainFormMdiChildActivate(object sender, System.EventArgs e)
{
CheckMdiList();
}
This is called when you 'open' or 'close' the child. The problem is that at that moment the child still exists, so it's still in the list.
Is this making things cleare of just the opposite?
Either way, I already want to thank anyone for the given help.
|
|
|
|
|
Jonckheere wrote:
Where do I put this check on the Mdichildren so I can be sure that when the Child is closed, but whatever method, the check is performed?
Why not create a timer that fires, say, every half a second, and do your updating from there? Apart from the Window menu, you can update your toolbar, status bar and so on.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hi all,
I want to know how to change a C# application to run in background from inside the program, i.e. the user can click a button in the GUI of the application, so that the application/or some of its process can run at background, so it won't compete resources with the other applications in foreground.
Thanks
Patrick
|
|
|
|
|
Hi!
Check out the usage of System.Threading.Thread - 'IsBackground' Property and use if it suits ur need.
Regs,
Manivannan.P
|
|
|
|
|
Hello .
Iam new to c#.
How a message to send to all clients in LAN network.
like "Net send" command
|
|
|
|
|
This has been covered in this forum many times. Whether or not you're new to programming or even just a particular language, basic research skills are a must in the field of development. Next time, please search first. You can search this site's articles using the search box at the top of every page, or click "Search comments" in every forum to search previous threads. You could also just google the entire web.
The simplest way is to just use "net send" using the Process class:
Process.Start("net", "send /domain Hello, world!"); The other way is to P/Invoke the native functions but requires you understand what P/Invoke is. If you want to go that route, I suggest you search for the previous threads about "net send" and you'll find links and examples, but the method above works just fine.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for your suggetion
I have another doubt will please help me? link below
http://www.codeproject.com/script/comments/forums.asp?msg=949594&forumid=1649#xx949594xx
|
|
|
|
|
I'm using log4net in my app to print debugging information. I have added code as follows
static QuestionGroup()
{
log = log4net.LogManager.GetLogger(typeof(QuestionGroup));
isDebugEnabled = log.IsDebugEnabled;
isInfoEnabled = log.IsInfoEnabled;
}
public QuestionGroup()
{
questionGroupId="questionGroup"+questionGroupCreated++;
heading="Place your heading here";
subHeading="Place your subheading here";
position=-1;
this.questionList=new ArrayList();
if(isDebugEnabled)
{
log.Debug("QuestionGroup created with id :"+questionGroupId);
}
}
but in the output window it give the error
log4net:ERROR No appender named [LogFileAppender] could be found.
how can I fix it
samitha
|
|
|
|
|
I have just started to use log4net too in my shareware and I think its a great little tool. I think you need to look at your config file and clean it up abit and have only the things in there that you want/need. In mine I have a section named LogFileAppender, here it that section of my config (had to add spaces to get the xml to show up correctly):
< appender name="LogFileAppender" type="log4net.Appender.FileAppender">
< param name="File" value="log-file.txt" />
< param name="AppendToFile" value="true" />
< layout type="log4net.Layout.PatternLayout">
< param name="Header" value="[Header]\r\n" />
< param name="Footer" value="[Footer]\r\n" />
< param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n" />
< /layout>
< /appender>
Steve Maier, MCSD MCAD
|
|
|
|
|
I'm getting the following messages
log4net:ERROR No appender named [LogFileAppender] could be found.
log4net: Appender named [LogFileAppender] not found.
log4net:ERROR No appenders could be found for category (Com.SriLogic.Qsurv.QBuilder.Gui.MainForm).
log4net:ERROR Please initialize the log4net system properly.
here is the config file
/**/
<?xml version="1.0" encoding="utf-8" ?>
<!-- .NET application configuration file
This file must have the exact same name as your application with
.config appended to it. For example if your application is testApp.exe
then the config file must be testApp.exe.config it mut also be in the
same directory as the application. -->
<configuration>
<!-- Register the section handler for the log4net section -->
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<startup>
<supportedRuntime version="V1.1.4322"/>
</startup>
<appSettings>
<add key="SerialQuestionID" value="1"/>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
<!-- This section contains the log4net configuration settings -->
<log4net debug="true">
<logger name="Com.SriLogic.Qsurv.QBuilder.Gui.MainForm">
<level value="INFO"/>
<appender-ref ref="LogFileAppender" />
</logger>
<!-- Define some output appenders -->
<appender name="LogFileAppender" type="log4net.Appender.FileAppender,log4net">
<!--param name="File" value="c:\\error-log.txt" /-->
<file value="C:\\error-log.txt" />
<param name="AppendToFile" value="true" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default priority -->
<root>
<priority value="INFO" />
<appender-ref ref="LogFileAppender" />
</root>
<!-- Specify the priority for some specific categories -->
<category name="Com.SriLogic.Qsurv">
<priority value="INFO" />
<appender-ref ref="LogFileAppender" />
</category>
</log4net>
</configuration>
/**/
how can I fix this?
samitha
|
|
|
|
|
In my file I have my "logger" section defined at the end of the file under my "root" section. I think that yours might need to move down because it does not know the definition of the LogFileAppender before its defined. I can email you my file if you want too.
Steve Maier, MCSD MCAD
|
|
|
|
|
Hi all,
I came across a case in which a dll and html page are integrated to launch an application in IE and I have no idea of what it is. It is an URL as below,
res://C:\file-path\example.dll/page.html
in the registry setting of the Internet Explorer, so when the user right click the page text inside the IE, the context menu will have the example appliction menu item, and via it the example application can be launched.
So how is the example.dll and page.html are integrated in this case ?
And how can I create a example dll and html page like this to launch an application ?
Thanks
Patrick
|
|
|
|
|
Hi,
I am not entirely sure what is the best way to create these type of files, but I use a program called "Resource Hacker" (ResHacker.exe) - it is a freeware utility that allows you to read the resources from a dll. You can extract icons, etc...
The example that I would refer to would be the "Outlook Today" page within outlwvw.dll (in the standard office path), you can change the page that is displayed in Outlook by using Resource Hacker. Works really nicely. I am sure that there would be a way to insert a new HTML page for external access using this?
Hope this is helpful,
DJ
|
|
|
|
|
Thanks DJ,
But I would like to know how to create a DLL like this by programming in c# and how to contruct the corresponding html also.
Patrick
|
|
|
|
|
See my reply for how to embed HTML files (and other files) in a library, which has nothing to do with C#, BTW.
If you want to know how to construct HTML documents, you best pick up a book on HTML or learn by example and view source for other sites in additional to reading about the tags (don't just guess at what they do). This is not the forum to teach you about writing HTML (it's not considered programming since HTML is not a programming language).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|