|
Eric Gunnerson (msft) wrote:
The way appdomains work takes a bit of mind-warping to figure out.
Hi Eric, i have had my mind warped already (partially)
I understand from your article how to use objects from remote domains in the main app domain, but how does it work the other way around?
Eg. You have main program with an object say A. In my case object A also contains a NetworkStream that should not be disconnected. I want to now load/unload "helper" assmeblies in a remote domain that can reference an instance of object A in the main app. Can this be done, without me landing up in a psychiatric ward?
Reading both parts of the graphing calculator article was already a great help, i cant find any examples on how to do the reverse as described above.
Thanking you in advance
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I think the way you'd do this would be to pass a MarshalByReference object as a parameter to the other app domain when you made a call. That should result in the other app domain having a proxy object to the object in the main app domain.
I haven't tried this, however.
|
|
|
|
|
Really curious why the 'where' statements that the OleDbDataAdaptors creates are excessively wordy...
What are they trying to accomplish here? Do automatic code creators get paid by the line? What is the point of the extra 250 lines of code?
Wouldn't just WHERE (CustomerID=?) work just fine?
this.oleDbDeleteCommand1.CommandText = @"DELETE FROM Customers WHERE (CustomerID = ?) AND (Address = ? OR ? IS NULL AND Address IS NULL) AND (City = ? OR ? IS NULL AND City IS NULL) AND (CompanyName = ?) AND (ContactName = ? OR ? IS NULL AND ContactName IS NULL) AND (ContactTitle = ? OR ? IS NULL AND ContactTitle IS NULL) AND (Country = ? OR ? IS NULL AND Country IS NULL) AND (Fax = ? OR ? IS NULL AND Fax IS NULL) AND (Phone = ? OR ? IS NULL AND Phone IS NULL) AND (PostalCode = ? OR ? IS NULL AND PostalCode IS NULL) AND (Region = ? OR ? IS NULL AND Region IS NULL)";<br />
And the parameter list...
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Address", System.Data.OleDb.OleDbType.VarWChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original, null));<br />
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Address1", System.Data.OleDb.OleDbType.VarWChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original, null));<br />
<br />
... x 10 times more
|
|
|
|
|
Ahhh... Optimistic Concurrency. Nevermind.
|
|
|
|
|
Is it possible to create a class, call it a, and make it implicity accept a reasonable cast, for example
string s = MyA;
???
I was thinking of writing a class called ConstString, for example, passing a string into the constructor, and then having it return the string when the object was used as a string. So I could do this
public void MyFunc (ConstString s)
and call it like this
MyFunc(ConstString(myString));
Oh, and if anyone reading has an answer to my XmlTextWriter problem from yesterday, it's still driving me mad.....
Thanks.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
|
|
|
|
|
Christian Graus wrote:
Is it possible to create a class, call it a, and make it implicity accept a reasonable cast, for example
string s = MyA;
???
using System;
class Nish
{
public static void Main()
{
string s = new Nish("Christian Graus");
Console.WriteLine(s);
}
public Nish(string s)
{
m_s = s;
}
public static implicit operator string(Nish a)
{
return a.m_s;
}
private string m_s;
}
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Thanks - looks like I win and C# loses. It's such a shame to find myself fighting the language.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
|
|
|
|
|
You don't need to do that for a string object. strings are immutable so no changes can be made to it.
All methods on string that would do any modification return a new string object containing the changes.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Thanks - I know that, I just wrote the first example that sprang to mind. The object I actually want to pass is an XmlNode, and I dunno that this will help, because once I get back the node, I can still call methods on it that change it.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
|
|
|
|
|
I am trying to use a library file that I created in MFC Visual C++. It
won't let me include it as a reference so I am assuming I need to do
something like this:
[DllImport("MyDLL.dll")]
private static extern bool Counter(out long lpCount);
However I don't just wanna import a method I wanna make an instance of the
class which is called CAppBar. Can anyone point me in the write direction
here? It would be a huge help thanks...
|
|
|
|
|
P/Invoke only lets you hook up to static functions; you can't create C++ instances, as the CLR and C++ rules for how classes work are quite a bit different.
To do this, you'd need to wrap it using the Managed Extensions to C++.
|
|
|
|
|
Welcome,
Have you got any example how to put Bitmap (created during working of application) and than put it (embedded) in RichTextBox control.
Bitmap is created in the memory (not reading from file).
thx
|
|
|
|
|
Hi
I have tried to do something similar and there seems to be 2 ways:
1. Easy - place bitmap object in clipboard and paste to richtextbox. Problem that u use the clipboard and mite "lose" data that still needs to be there.
2. Hard - Create a RTF file in a word processor with required bitmap, save the file. Now add that to the Rtf of the richtextbox. This could coause many problems though
3. Ideal solution - Every stick together and make a proper WordProcessingTextBox with all the features we always wanted . Like highlighting
Hope this helps
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
Hi
I have tried to do something similar and there seems to be 2 ways:
1. Easy - place bitmap object in clipboard and paste to richtextbox. Problem that u use the clipboard and mite "lose" data that still needs to be there.
Hmm I did't think about it... but how to copy bitmap from Form (for example I would like to write some kind of chart and put it into rtf)
leppie wrote:
2. Hard - Create a RTF file in a word processor with required bitmap, save the file. Now add that to the Rtf of the richtextbox. This could coause many problems though
In my case it couldn't be done.
leppie wrote:
3. Ideal solution - Every stick together and make a proper WordProcessingTextBox with all the features we always wanted . Like highlighting
That's cool. But unfortunately I don't have time to do it
(but maybe in future it is good idea
|
|
|
|
|
I am looking for something similar to a feature Delphi has, that allows you to
- create a "Data Module"
- add database components (connections, tables, views)
- use the data module in any form (it works with the visual tools too).
I can't seem to find anything similar for a Windows Forms C# application.
What I would like to do, is have one database connection always open, and available to any form.
It's quite trivial to do it in code, but how can you make the visual designer tools "see" this connection?
|
|
|
|
|
I try to write a .vsz file, but when I use it in vs.net, vs.net always told me "Could not run xxx.vsz file"!
I'm amumu, and you?
|
|
|
|
|
How do I detect, at runtime, what the .NET Framework Version is?
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
System.Version
I'm amumu, and you?
|
|
|
|
|
System.Version is a class that represents a version number; by itself it doesn't tell you the version number of the framework but System.Environment.Version will tell you the version of the CLR.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Hey, thanks for the reply, James. Apparently, though, the .NET Framework Version is not the same as the script directory that ASP.NET uses. What I mean, is that System.Environment.Version returns 1.0.3705.209, but the ASP.NET script files (WebUIValidation.js, etc.) are in a folder called 1_0_3705_272. Ideally, I'd like to be able to get this folder without having to enumerate its siblings, and look for the highest revision number.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
why are you trying to muck around with the asp.net script files?
|
|
|
|
|
I'm not trying to modify them or anything. I created a custom validator (that implements IValidator, but doesn't derive from BaseValidator), and was hoping I could just use the available script for client side validation, rather than have to rewrite my own.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
BaseValidator gets the path to the script files from the internal static System.Web.UI.Util.GetScriptLocation method, which gets some of its info from the internal System.Web.Util.VersionInfo.SystemWebVersion property.
GetScriptLocation looks up the "clientScriptsLocation" setting in the machine.config file. but that string has parameters which are filled in by SystemWebVersion.
You might be best off either using reflection to get to the GetScriptLocation method, or querying the .config file for the root path, and then scanning that folder for the highest version.
|
|
|
|
|
Hi, I have a little problem with the 'Clipboard' class. I am attempting to transfer data from the windows clipboard to a bitmap object and appear to be leaking memory. The following code placed in a button on a windows form will cause a significant amount of memory to be allocated and only partially freed. You must manually 'copy' an image onto the clipboard prior to running this code.
System.Drawing.Bitmap bm;
IDataObject iData;
iData = (IDataObject) Clipboard.GetDataObject();
for (int i = 0; i < 100; i++)
{
if (iData.GetDataPresent(DataFormats.Bitmap))
{
bm = (Bitmap) iData.GetData(DataFormats.Bitmap);
if (bm != null)
{
bm = null;
}
else Console.WriteLine("Bitmap was NULL");
}
}
If the 'bm=(Bitmap)...' line is commented out no memory will leak.
I have been using an approximately 512x512x32 BMP for my tests.
Note : This code is simply to test the leaking problem. The real code places a different image on the clipboard every time through the loop and then works with the data in the if (bm != null) {...} block.
|
|
|
|
|
How are you checking the memory use? There's nothing in your code that forces the bitmap to be freed, so memory is going to be hanging around until a GC happens.
You could call bm.Dispose() to free it early.
|
|
|
|