|
Thanks James for the Info'.
I never knew anything on reJITing ... but I couldnt follow when you said the underlying IL has changed.. u mean how the m/c code is aligned or something of that sort ..Any idea on how do I do the install time JIT stuff, I remember long ago I read an article which said the JITing happens not once or all at a time but only when a particular portion of the code is used eg. a method call is done.
thanks
Kannan
|
|
|
|
|
Kannan Kalyanaraman wrote:
but I couldnt follow when you said the underlying IL has changed..
In a .NET application it is possible to change the image of the assembly at runtime. John Lam does this in his aspect weaver, and the JITter does this whenever it JITs a method [before a method is JITted the x86 has a jmp to a stub function that does the JIT, that jmp is then replaced once the method has been JITted].
Kannan Kalyanaraman wrote:
Any idea on how do I do the install time JIT stuff
ngen is the install-time JIT utility, so you'd just run that program during your setup.
Kannan Kalyanaraman wrote:
I remember long ago I read an article which said the JITing happens not once or all at a time but only when a particular portion of the code is used eg. a method call is done.
The runtime JIT works this way. When a method is JITted any method calls are looked up to see if the method has already been JITted, if it has it outputs an x86 jmp instruction to that method's x86 code; if it hasn't been JITted it instead outputs a jmp instruction to a stub function, which when executed will start the JIT process.
James
Simplicity Rules!
|
|
|
|
|
I'm currently trying to get a remote object, using Remoting... I can get the object, but I can't grab a event the object fires. This is all example code and I just can't seem to get it work. I get the object, but the remote object doesn't see the client sign up to watch for the event, so it never fires the event. Or if you have a better way for my Server and Client to communicate, don't hesitate to share.
Any help with would greatly appreciated. If you have more questions, please email me.
[Server]
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace Test.Remote
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Server
{
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "Hi", WellKnownObjectMode.SingleCall);
Console.WriteLine("Hit to exit");
Console.ReadLine();
}
}
}
[Client]
using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace Test.Remote
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Client
{
[STAThread]
static void Main(string[] args)
{
//RemotingConfiguration.Configure("Client.exe.config");
ChannelServices.RegisterChannel(new TcpClientChannel());
RemoteObject obj = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "tcp://localhost:8086/Hi");
EventSink sink = new EventSink();
// register client sink in server - subscribe to event
obj.Status += new StatusEvent(sink.StatusHandler);
obj.LongWorking(5000);
// unsubscribe to event
obj.Status -= new StatusEvent(sink.StatusHandler);
obj.LongWorking(5000);
Console.WriteLine("Hit to exit");
Console.ReadLine();
}
}
}
[RemoteObject]
using System;
namespace Test.Remote
{
[Serializable]
public class StatusEventArgs
{
public StatusEventArgs(string m)
{
message = m;
}
public string Message
{
get
{
return message;
}
set
{
message = value;
}
}
private string message;
}
public delegate void StatusEvent(object sender, StatusEventArgs e);
/// <summary>
/// Summary description for Class1.
/// </summary>
public class RemoteObject : MarshalByRefObject
{
public RemoteObject()
{
Console.WriteLine("RemoteObject constructor called");
}
public event StatusEvent Status;
public void LongWorking(int ms)
{
Console.WriteLine("RemoteObject: LongWorking() Started");
StatusEventArgs e = new StatusEventArgs(
"Message for Client: LongWorking() Started");
// fire event
if (Status != null)
{
Console.WriteLine("RemoteObject: Firing Starting Event");
Status(this, e);
}
System.Threading.Thread.Sleep(ms);
e.Message = "Message for Client: LongWorking() Ending";
// fire ending event
if (Status != null)
{
Console.WriteLine("RemoteObject: Firing Ending Event");
Status(this, e);
}
Console.WriteLine("RemoteObject: LongWorking() Ending");
}
}
}
[EventSink]
using System;
using System.Runtime.Remoting.Messaging;
namespace Test.Remote
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class EventSink : MarshalByRefObject
{
public EventSink()
{
Console.WriteLine("EventSink: Constructor called");
}
[OneWay]
public void StatusHandler(object sender, StatusEventArgs e)
{
Console.WriteLine("EventSink: Event occurred: " + e.Message);
}
}
}
-wzrd
wizardque@yahoo.com
|
|
|
|
|
I would like to write a Windows app that looks like (e.g.) Microsoft Outlook. I thought it would be easy - I hosted a WebBrowser COM control in my Windows form, and pointed it at a frameset containing the graphic buttons on the left. The buttons loaded different local html pages on the right. So far so good.
Now I want to host some Windows.Forms controls in one of my pages on the right. My idea is to derive my own controls from Windows.Forms controls, and have them interact directly with my app. I followed some tutorials on doing this, but they all assume the html page is on a Web Server. Mine is local ("file://" instead of "http://").
So I created an object like this...
< object id="testControl" classid="file:MyControls.dll#MyControls.TestControl" height="300" width="300" VIEWASTEXT> < /object>
But it doesn't work. Is it something I'm doing, or a bug, or isn't it supposed to be possible?
|
|
|
|
|
Hi all,
What is the best way to convert C style structures to C#.
I have converted the following C structure
typedef struct {
ISC_DATE timestamp_date;
ISC_TIME timestamp_time;
} ISC_TIMESTAMP;
to
public struct ISC_TIMESTAMP
{
long TIMESTAMP_DATE;
ulong TIMESTAMP_TIME;
};
Is this correct or should I be using another more C# style like..
[StructLayout(LayoutKind.Sequential)]
public class ISC_TIMESTAMP
{
// rest of code goes here
}
How about this more complicated C structure...
typedef struct blobcallback {
short (ISC_FAR *blob_get_segment)
(void ISC_FAR* hnd, unsigned char* buffer, ISC_USHORT buf_size, ISC_USHORT* result_len);
void ISC_FAR *blob_handle;
ISC_LONG blob_number_segments;
ISC_LONG blob_max_segment;
ISC_LONG blob_total_length;
void (ISC_FAR *blob_put_segment)
(void ISC_FAR* hnd, unsigned char* buffer, ISC_USHORT buf_size);
ISC_LONG (ISC_FAR *blob_lseek)
(void ISC_FAR* hnd, ISC_USHORT mode, ISC_LONG offset);
} ISC_FAR *BLOBCALLBACK;
What is the best way to handle this type of conversion.
Sincerely,
Dominique.
|
|
|
|
|
Dominique wrote:
public struct ISC_TIMESTAMP
{
long TIMESTAMP_DATE;
ulong TIMESTAMP_TIME;
};
Is this correct or should I be using another more C# style like..
[StructLayout(LayoutKind.Sequential)]
public class ISC_TIMESTAMP
{
}
You need to use a combination of the two, keep it a struct but apply the StructLayout attribute its your only guarantee that the data will stay in that order; otherwise the compiler could move fields around to better align the data.
Dominique wrote:
struct blobcallback {
short (ISC_FAR *blob_get_segment)
(void ISC_FAR* hnd, unsigned char* buffer, ISC_USHORT buf_size, ISC_USHORT* result_len);
void ISC_FAR *blob_handle;
ISC_LONG blob_number_segments;
ISC_LONG blob_max_segment;
ISC_LONG blob_total_length;
void (ISC_FAR *blob_put_segment)
(void ISC_FAR* hnd, unsigned char* buffer, ISC_USHORT buf_size);
ISC_LONG (ISC_FAR *blob_lseek)
(void ISC_FAR* hnd, ISC_USHORT mode, ISC_LONG offset);
}
Call backs are done with delegates, there is an article somewhere on CP that shows how to use a callback for the EnumWindows function, i think it was how to programmatcally control IE.
void is usually a object
When you have a character buffer pass in a StringBuilder object
A ** (pointer to a pointer) usually uses the 'out' keyword followed by its type, a pointer is usually a reference ('ref').
HTH,
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
Hello!
I'm a computer science student and want to start coding with Visual Studio .Net in C#. As I want to use my Apps commercially, the Student-licence doesn't seem to be usefull for me. On the other hand I doesn't have the money to buy the professional version of .NET. And I don't nedd any Server things or other languages than C#. So The Visual C# .NET Standard edition seems to be the right thing for me. So I looked at the comparison-table at http://msdn.microsoft.com/vcsharp/howtobuy/choosing.asp and there it says, that NOT supported are:
-Class Libraries
Create reusable class library components using the Class Library template
Does that mean, I cannot program class libraries?!? Or is only the template missing?
-Windows Control Libraries
Construct custom user interface controls for Windows Forms using the Windows Control Library template.
The same question: Does that mean, I cannot program custom control libraries, or is only the template missing?
If you have any serious warnings NOT to buy this edition, please let me know.
Mario
|
|
|
|
|
Mario, I bought the standard version as well and ran into the same issues you have. There are quiet a few templates that are missing. However, after doing some searches, MS has claimed that they inadvertently left of some of the templates in the standard edition and will be providing an update (Not sure which templates they are referring to). With that said some people have found ways to add various templates back in. Here is a link for the class library template. It works great.
http://groups.google.com/groups?hl=en&lr=lang_en&ie=ISO-8859-1&oe=ISO-8859-1&th=1610d3f841479209&rnum=1
In response to your questions, you can create libraries and controls, it's just a manual process. The templates make things much easier
|
|
|
|
|
Must i write the codes to parse a email message from a pop3 server myself ?
thanks
Thanks to those people with an "opensource" heart. they make me love what I am doing.
|
|
|
|
|
SoftArtisans has created a free POP3 control that you can use.
SoftArtisans POP3 Control - Source Code is included.
It doesn't look like it has been upgraded from Beta 2 yet, but the changes should be fairly minor.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
James T. Johnson wrote:
SoftArtisans has created a free POP3 control that you can use.
SoftArtisans POP3 Control - Source Code is included.
It doesn't look like it has been upgraded from Beta 2 yet, but the changes should be fairly minor
Thanks James
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Brian Delahunty wrote:
one of my boys on the inside instead of the outside
benjymous wrote:
All the male CP inhabitants cross their legs in unison
|
|
|
|
|
I wanna expand the ability of some class provided by framework like Bitmap, but I find it modified by sealed.
How can i do with it?
Another similar problem is when i try to inherit XmlElement, I find its construction is modified by internal. Then the compiler find it as an error. any solution to bypass?
|
|
|
|
|
I had the same problem with SqlDataReader. I just created a new class that wrapped each SqlDataReader method and property and then inherited from my class. It kind of sucks but I don't think there is any other way.
|
|
|
|
|
Well, the wrapper is boring but i fininally made it.
I think if Microsoft holds its position on sealing their class, then it will be a good idea to design a wizard to automatively build a wrapper. Hope C#'s reflection ability will make it possible.
Do you think so?
|
|
|
|
|
Yes it stinks. The reason for Bitmap being sealed is because it is a wrapper around GDI+ which is a native DLL. .NET doesn't support inheritence from a native image, yet anyway
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
I can't speak for them all...
but some are sealed for performance reasons.
and I quote from "Applied Microsoft .NET Framework Programming":
" the CLR knows the exact layout of the fields defined within the String type, and the CLR accesses these feilds directly." ... If String were not sealed, "you could add your own fields, which would break the assumptions the CLR makes, In addition, you could break some assumptions that the CLR has made about String objects being immutable."
|
|
|
|
|
Andy Smith wrote:
and I quote from "Applied Microsoft .NET Framework Programming":
" the CLR knows the exact layout
Here is Mircosoft "knowing" everything again...
Nick Parker
|
|
|
|
|
How can I draw a bitmap button with a transparent background.
Im using the code below to try and do this but its not working how it should.
Bitmap b = new Bitmap("D:\\-=[Pics]=-\\test.jpg");
b.MakeTransparent(b.GetPixel(0,0));
pe.Graphics.FillRectangle (Brushes.Transparent,ClientRectangle);
pe.Graphics.DrawImage(b,ClientRectangle);
Im trying to paint the button transparent then draw an image whose transparency key is the same as the color at 0,0 of the bitmap. It sort of works but when the image is drawn on the button the background looks more like swiss cheese than transparent.
Any help would be great.
Thanks Danny
|
|
|
|
|
Try opening the JPEG in an image viewer, I bet your background color got mangled during the compression of the file resulting in a slightly different color in spots (but nothing the human eye would notice).
If possible you should stick to lossless image formats such as: BMP, GIF, PNG
HTH,
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
What could be done in C# which would add much in language expressiveness
without any penalties to security and efficiency.
Before implement any language feature I think designers discussed them many
times and surely they analyzed any similar implementation in all the languages
(not only C,C++, but Java, FoxPro, Pascal, ADA, etc). So C# is not just a
revamped dialect version of C++ + garbage collection (such attempts to create
garbage collection feature to C++ have been made many times), that's why my
question is purely ritoric: why they didn't do that? What is that ... read
below.
In language description we read that in order to go out of innermost
cycle we should use goto operator. Yes, of course, but wouldn't it be better to
write something like this?
for (condition_1)
{
....
while(condition_2)
{
....
break level; // level see next comment
/* level - int expression, if 0 means regular break;
1 - means one level up, in this particular case
means exit from for cycle
*/
...
continue level; // see comments above
}
...
}
I've been wondering why it hadn't been done since the first C-compilers
appeared, I worked then on PDP11. Java made it better, but still it is too
similar to goto..
Another question: Look at this snippet of code
if(codition_1)
{
....//do smth
}
else
{
if(codition_2)
{
....//do smth
}
else
{
if(codition_3)
{
....//do smth
}
else
{
}
}
}
isn't it ugly? Imagine 20 conditions analyzed, what will happen to nesting
level? Then compare to this: (borrowed from FoxPro,Clipper...)
switch
{
case (condition_1)
.... // no need of break, that has become obligatory in C# !!!
case (condition_1)
...
default:
}
By the way switch operator in old C-style definition could be used as well,
they wouldn't interfere with each other.
I don't see any reasons not to implement such useful features.
Alex .
ovarlamov@sprint.ca
|
|
|
|
|
I agree with you that C# switch statement is unneccesarily poor. It is such things that make me almost want to move to VB.Net.
VB and C# are on the same level, performance-wise, and VB has some _great_ syntax niceties such as a GOOD switch statement ( Select/Case ) and the With statement.
Although, in the long run I doubt i'll ever switch to vb.net... if only for the reason that I fully expect that a programmer who has "c#" on his resume can demand a higher pay than one with "VB.net" on it; regardless if that is an intelligent decision.
|
|
|
|
|
Hi Guys,
I need a little help.
The scenario is as follows,
I have an interface I,
Class C implements I.
C compiles to dll.
In another project
I want to Assembly.Load C
and cast it to interface I so that I can use the methods in C
Is this possible. What do I need to do? I'm very new to Assemblies!
If not what the alternatives?
Please help!
- Tariq
|
|
|
|
|
Yes its quite possible, I've written an article that does just that Using reflection to extend .NET programs.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
Hi, I would like to check if there is running any instance of my application, in order to set the focus on it if the user try to start a new one.
Any idea?
Thank you.
|
|
|
|
|
Something like this:
Int32 RunningProcesses = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName ).Length;
if ( RunningProcesses >= 1 ) {
MessageBox.Show( "already running the program" );
}
--
David Wengier
Sonork ID: 100.14177 - Ch00k
|
|
|
|
|