|
I agree on all points
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi,
I've got a few classes that implement IDisposable to clean up their resources. In a windows forms app, I would create the objects in the forms constructor and dispose of the objects in the overridden dispose method.
In WPF, the Window class doesn't implement IDisposeable. Where should I dispose of these objects?
I'm quite new to WPF, so maybe I'm just missing something obvious.
Can anyone help.
Simon
|
|
|
|
|
The WPF Window class doesn't implement IDisposable, because it doesn't have anything to dispose.
You can create your own Window class (say MyWindow) that derives from Window and implements IDisposable. Then either you can explicitly call Dispose when you are done with your Window, or you can simply let the finalizer call it for you.
Check this[^] and this[^] out, for more info on how to implement IDisposable properly.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
The problem won't be solved by implementing the dispose pattern on the window, I will still be left with a window class that doesn't get disposed as there is nowwhere to call dispose on the Window from.
In WPF the entry point is auto generated and looks like this:
[System.STAThreadAttribute()]<br />
[System.Diagnostics.DebuggerNonUserCodeAttribute()]<br />
public static void Main() {<br />
WpfApplication1.App app = new WpfApplication1.App();<br />
app.InitializeComponent();<br />
app.Run();<br />
}
(No window class anywhere), and the app.xml file looks like this
<Application x:Class="WpfApplication1.App"<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
StartupUri="Window1.xaml"><br />
<Application.Resources><br />
<br />
</Application.Resources><br />
</Application>
I don't have control over the creation of the window class, and it won't get disposed of. I tried it, and all that happens is the finaliser gets triggered when the app is closed.
What I've done for now is to manually implement the app entry point so I have control over the window creation:
public static void Main()<br />
{<br />
WpfApplication1.App app = new WpfApplication1.App();<br />
using (Window1 mainWindow = new Window1())<br />
{<br />
app.Run(mainWindow );<br />
}<br />
}
But this doesn't quite feel like the 'WPF way'. I have no app.xaml file.
Is there a way of doing this without manually implementing the the app entry point, or is this how it should be done?
It's a minor point really, It works fine the way I've done it, just I wondered if there's a proper way of doing it.
Simon
|
|
|
|
|
Following the proper implementation of IDisposable, the finalizer should call the Dispose method for you. So if your application is shutting down, and the finalizer is called on the Window, then Dispose should be called. Are you saying that Dispose is not being called in this scenario?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Sorry, thats not what I meant, I'm not very good at explaining.
Yes the finalizer is getting called, and yes that triggers the dispose method, but following the pattern, it calls the dispose method and passes false, which means it doesn't clean up managed resources, instead they are left for their own finalizers to be triggered to clean them up, and so on, which means my whole stack of objects are all left waiting for their finalisers to clean them up which is a bit messy, which is what I meant when I said "it won't get disposed of...all that happens is the finaliser gets triggered."
Also, finalizers aren't guranteed to be called.
I think the way I've done it is the best solution, I get deterministic clean up, and no worries about relying on the finaliser.
Thanks for helping.
Simon
|
|
|
|
|
I have a more or less simple question on WPF (to be precise, on XAML)
I want to rotate a textbox, but when I add a RotationTransformer with an angle of 90°, the box is rotated - but not on the same position anymore!
Is there some method to rotate it in place arround the control's center instead of the upper-left corner?
Thanks in advance!
|
|
|
|
|
Check this[^] out.
Basically, you need to add the following to your textbox definition:
RenderTransformOrigin="0.5,0.5"
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I want a message box with Yes and No option asp.net 1.0 web application
how can i do this
|
|
|
|
|
swami samarth wrote: I want a message box with Yes and No option asp.net 1.0 web application
ASP.NET 1.0? The latest version is 3.5. You should really consider upgrading.
You could do this with the Javascript confirm[^] method.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Hi,
You will have to do it using Javascript. Try following code in your code behind on the button where you want this box.
cmdSubmit.Attributes.Add("onclick", "return window.confirm('Are you sure!!!');");
Regards
Nav
|
|
|
|
|
Hi all,
Please advise me some certification ..in .net .. i am new in .net but have some exposoure in VC++ and C# with sql server...
vikas da
|
|
|
|
|
tasumisra wrote: Please advise me some certification ..in .net .. i am new in .net but have some exposoure in VC++ and C# with sql server...
C# is .NET...
You should only consider working towards any .NET certification if you really know your stuff. If you are new to .NET, you should spend a couple of years working with it and knowing the framework inside out. Then you will be ready to obtain the certification.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
|
I'd like to monitor the behaviour of a complex UI Framework (with Plugins etc.)
Is it somehow possible for a .NET Thread (or by means of win32 API) to monitor when
1) - other Threads
2) - or new windows message queues (for user interfaces)
3) - or simply new window handles are created within the process
within the same process are started/created without polling e.g. the
System.Diagnostics.Process.Threads Property
i.e. detecting these situations 1-3 "event like" from another thread.
Thanks
Martin
|
|
|
|
|
|
hello,I have this exception when i run my host service:
"HTTP was unable to enter the URL http:// +: 2605/SolutionWCF/WCFLibrarie. The process does not have access rights to that namespace"
host code:
namespace Host
{
class Program
{
static void Main(string[] args)
{
Uri baseAdresse = new Uri("http://localhost:2605/SolutionWCF/WCFLibrarie");
ServiceHost monHost = new System.ServiceModel.ServiceHost(typeof(WCFLibrarie.Class1),baseAdresse);
try
{
monHost.AddServiceEndpoint(typeof(monPremierWCF.interfaceWCF), new WSHttpBinding(), "WCFLibrarie.Class1");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
monHost.Description.Behaviors.Add(smb);
monHost.Open();
Console.WriteLine("les services sont maintenant disponibles.............. ");
Console.WriteLine("Cliquer sur <ENTRER> pour fermer les services!!!");
Console.WriteLine();
Console.ReadLine();
monHost.Close();
}
catch (CommunicationException ex)
{
Console.WriteLine("Une Exception est generée{0}", ex.Message);
monHost.Abort();
}
}
}
}
Contract:
amespace monPremierWCF
{
[System.ServiceModel.ServiceContract]
public interface interfaceWCF
{
[System.ServiceModel.OperationContractAttribute]
string majiscule(string chaine);
[System.ServiceModel.OperationContractAttribute]
string mainiscule(string chaine);
}
}
service:
namespace WCFLibrarie
{
public class Class1 : monPremierWCF.interfaceWCF
{
#region interfaceWCF Members
string monPremierWCF.interfaceWCF.majiscule(string chaine)
{
return string.Format("hello {0}", "hicham").ToUpper();
}
string monPremierWCF.interfaceWCF.mainiscule(string chaine)
{
return string.Format("hello {0}", "hicham").ToLower();
}
#endregion
}
}
my App turn on :
Win vista ultimate
Thanks.
sdfrt
|
|
|
|
|
|
Hello,
I'm currently looking into obfuscation and protection schemes for .Net based projects and stumbled on something called .Net Reactor today (http://www.eziriz.com/[^]) and I would like your thoughts about it, especially if you have some experience with it.
Also, if someone with experience in this field can spare some time writing a few lines with do's and dont's regarding .Net code protection I would be grateful.
Thanks in advance,
|
|
|
|
|
Do protect your application if there really is some IP there to protect.
Don't bother if there isn't. Generally this is the case - any cool idea you have is going to be in what the app does, not how its coded...
We don't obfuscate any of our products yet - theres just no point. If someone wants to duplicate your program then they will, from scratch. They aren't going to risk looking at your code, because that will contaminate their devs. If its that good an idea they'll do it clean room, and theres nothing your obfuscator can do
Staying ahead of the game is a better strategy
|
|
|
|
|
Thanks for the input, it's made me think again about using obfuscation and such things.
That said, is it possible to protect (or at least make it harder) against circumventing a time restriction or similar sharware-related limitations in a .Net application? I'd have to say 'no', but please prove me wrong
Thanks,
|
|
|
|
|
Well an obfuscator would certainly help there. That said you have to ask yourself how many users are likely to try to edit the IL in your assemblies to bypass a trial period.
If their time is that worthless to them, well they probably can't afford to pay anyway.
We don't bother with any serious protection on our software for that reason. Our main product we give out free for non-commercial use - a few businesses have used the free one on the side, but got a license after they shipped (usually in their project implementation review... "Is there anything we forgot?"... oh software licenses!).
|
|
|
|
|
Thanks for the input. Have a good weekend.
|
|
|
|
|
No worries mate, you too.
|
|
|
|
|
I'm working on a WCF service project that creates a listener thread for TCP messages, and everything appears to work just fine except for shutting down the service. Here's a simple example that illustrates the problem:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,ConcurrencyMode=ConcurrencyMode.Multiple)]
public class Service1 : IService1, IDisposable
{
private void ThreadFn()
{
bool b = true;
while(b)
{
//do something
Thread.Sleep(1000);
}
}
private Thread m_Thread;
public Service1()
{
m_Thread = new Thread(new ThreadStart(this.ThreadFn));
m_Thread.Start();
}
public void Dispose()
{
m_Thread.Abort();
}
~Service1()
{
Dispose();
}
}
As you can see, this is a singleton service that creates a thread when the host starts, and kills the thread when the service is disposed. Unfortunately, there does not seem to be any way to reliably detect when a service is unloaded by the host. I've tried binding to the AppDomain.Unload and AppDomain.HostProcessExit events, however if Visual Studio hosts the service, these events are never fired. I've also tried creating a custom IInstanceProvider, but this only tells me when a method invocation is performed, and even then only when the InstanceContextMode is changed from Single. I want to be able to move the service into different hosting frameworks, so I'd like a solution that is an generic as possible. Does anyone have any suggestions?
Thanks,
Chris
|
|
|
|