|
If your goal is to have the user-interface thread run normally until the background thread dies, I would suggest having a 'quitNow' variable which is set by the background thread and polled in the main thread. The simplest approach to accomplishing that would be to have a timer that checks the 'quitNow' variable every 100ms or so. If you want to avoid the CPU overhead of doing that, you might be able to have the the timer disabled until the background thread enables it to signal its completion. I'm not sure if timer.enabled can be accessed between threads, though. If it can't, you may have to do something like:
Sub EnableKillMeTimer
If InvokeRequired then
BeginInvoke(New MethodInvoker(AddressOf EnableKillMeTimer))
Else
tmrKillMe.Enabled = True
Endif
End Sub While an approach like the above could probably be used to have the main form execute me.close, using a timer could make things a little nicer in case the main form doesn't want to close quite instantly.
|
|
|
|
|
Hey,
I have a Word 2003 Plug-in written in VS 2008.
In the plug-in startup method I create a button (or find it if it's already made) and assign an eventhandler to it:
m_SaveButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(SaveDoc_Click);
m_SaveButton is a global variable (Office.CommandBarButton m_SaveButton; )
Everything works fine until I have opened a document, then the eventhandlers for my button is not called anymore.
Any idea what's going on?
- Anders
|
|
|
|
|
Suppose we got the following code snippet:
var a = new {i=1, j=2};
How to assign a value for the specific field of that variable? I mean, something like this:
a.i = 5;
thanks for help
|
|
|
|
|
Yoyosch wrote: How to assign a value for the specific field of that variable?
You can't.
When you create an anonymous type the following code is generated:
private static void Main(string[] args)
{
var a;
a = new <>f__AnonymousType0<int, int>(1, 2);
return;
}
The special class <>f_AnonymousType0 looks like this:
[CompilerGenerated, DebuggerDisplay(@"\{ i = {i}, j = {j} }", Type="<Anonymous Type>")]
internal sealed class <>f__AnonymousType0<<i>j__TPar, <j>j__TPar>
{
[DebuggerBrowsable(0)]
private readonly <i>j__TPar <i>i__Field;
[DebuggerBrowsable(0)]
private readonly <j>j__TPar <j>i__Field;
[DebuggerHidden]
public <>f__AnonymousType0(<i>j__TPar i, <j>j__TPar j);
[DebuggerHidden]
public override bool Equals(object value);
[DebuggerHidden]
public override int GetHashCode();
[DebuggerHidden]
public override string ToString();
public <i>j__TPar i { get; }
public <j>j__TPar j { get; }
}
As you can see, there are no setters on any of those properties.
|
|
|
|
|
Hello
i have used AxSHDocVw.AxWebBrowser in my application. i want to block popup windows for my code. How do i go about it.
i tried doing
private void axWebBrowser1_NewWindow2(object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow2Event e)
{
e.ppDisp = null;
e.cancel = true;
}
But this is not helping
Can i get help over it?
|
|
|
|
|
have you tried catching the NewWindow3 event?
|
|
|
|
|
newWindow3 is used for Xp?
can i used in my code?
|
|
|
|
|
|
static ISettings settings = null;
public static Categories Current
{
get
{
if (_categories == null)
{
LoadCategories();
}
return _categories;
}
}
private static void LoadCategories()
{
using (FileStream stream= settings.GetCategoryFileStream())
{
.....
}
} I am trying to test the Current property. It is calling LoadCategories method and this method is using an external file. So I am trying to mock the external file call. For doing this, I need to supply ISettings instance explicitly. How do I supply it in this scenario ?
|
|
|
|
|
Your formatting is off - could you fix it so that I can see the rest of your message please?
|
|
|
|
|
Pete O'Hanlon wrote: Your formatting is off
I can see that correctly. I have not pasted the entire code. Do you mean that ?
|
|
|
|
|
Nope. I can see the message up until "So I am trying to mock the external file call" but you've got this enclosed in a code block section so it doesn't wrap.
|
|
|
|
|
Ok- here is the continuation.
For doing this, I need to supply ISettings instance explicitly. How do I supply it in this scenario ? I had some reading on Singleton Dependency Injection[^], but looks like it won't help much.
|
|
|
|
|
Why wouldn't you just set the dependency as a static property on the class?
|
|
|
|
|
I know it will work. But each time I use Current property, I have to set the settings. I guess it is not a good design.
|
|
|
|
|
What about something like this:
public static SingletonClass
{
private static ISettings _settings;
public static ISettings Settings {get; set;}
static SingletonClass()
{
_settings = new RealImplementationOfSettings();
}
}
What are you using for dependency injection (castle, structure map)?
Disclaimer: I am very new to TDD, I am sure on of the experts would probably tell you to do something completely different...
|
|
|
|
|
Ok - looks good. I will give a try. Thanks
|
|
|
|
|
I have a WebService/WebMethod that has a object array parameter. On of the elements of this array might contain a DBNull. When i try to pass a array with a DBNull element, I get the folllowing message:
The type System.DBNull was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
I have tried XmlInclude and SoapInclude with no success.
Web Service:
[WebMethod]
[System.Xml.Serialization.XmlInclude(typeof(DBNull))]
public string HelloWorld(object[] x) {
return "Hello World";
}
Consumer (Web Site):
object[] myarray = new object[1];
myarray[0] = DBNull.Value;
ServiceWS.Service serv = new ServiceWS.Service();
serv.HelloWorld(myarray);
|
|
|
|
|
Just use null, I dont think DBNull is XmlSerializable.
|
|
|
|
|
On page load in my web project I do processing and database record writing depending on which page was last and how the user has got there. It has dawned on my that I have forgotten about the browser back button...this is now causing my navigation nightmares. Can I tell if the page was arrived at via the browser back button in my C# code behind. If so I don't want to write any DB records. Simple really....
if browser.control = back
{
then nothing...
}
I can bet my last Euro that it is not going to be simple at all...
Any help very welcome..
|
|
|
|
|
Welcome to web development...
The best way to make the page not cachable, and hence it will be loaded every time it is accessed, even with the back button.
|
|
|
|
|
Hi, page load does work everytime but the processing inside needs to be conditional on if the page was assessed using the browser back button...I was wondering if I can tell via C#?
|
|
|
|
|
Maybe check the referrer field?
|
|
|
|
|
The refferer field??
Is this in the URL?
|
|
|
|
|
I am no expert in this area... however I know our web page designer had similar problems.
I could make one suggestion which is if you can keep track of the previous page then if you return to that page there is a chance the back button was pressed - although the user could have navigated there via a link as well I guess...
Oh well as I said I am no expert...
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|