|
And this is exactly what needs to be done. The secondary bitmap needs to be created each time (or at least cleared, but there's not really any performance benefit to that for simple compat bitmaps). Just because a class is being instantiated in .NET doesn't mean it's a heavy object. Many times it simply encapsulates an HDC or something and contains few to no fields (fields are what consume memory - not methods). The methods are just gravy, so to speak. They act on the fields (or other data passed to them), so if they are wrapping an HDC for a compat bitmap in order to run methods on it (encapsulation), then it's make it easier to use within code. Why duplicate all that code when you can have an encapsulating class handle it. That's what encapsulation's all about.
If you haven't implemented double buffering natively, I suggest you give it a try. This may shed some light on what's going on exactly.
Note that in some platforms and frameworks like DirectX, flipping buffers often yields better performance but both buffers (can be more than two, too) are typically "heavier" objects with transformations tied to them (it greatly depends on how you develop such code), so clearing them after flipping (or before) is better.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I didnt say its the heavy object but allocation of the memory could be the problem. So what is faster? Alloc 800x600x3bytes or fill the block of memory with zero ? I think the second one.
Wizard_01
|
|
|
|
|
IDGenerator.cs
--------------
public class IDGenerator {
int min, max;
public IDGenerator () {
this.min = 1000000;
this.max = 9999999;
}
public string GetID () {
Random r = new Random(unchecked((int)DateTime.Now.Ticks));
String myNumber = r.Next(min,max).ToString("00000");
r = null;
return myNumber;
}
}</
MyMath.cs
---------
class MyMath {
public static void Main() {
IDGenerator MyGenerator = new IDGenerator();
for (int x = 0; x < 5; x++) {
Console.WriteLine ("Random Number " + x + ": " + MyGenerator.GetID());
}
}
}
I am using above code to create 5 random numbers... however my results are like below:
Random Number 0: 3838931
Random Number 1: 1684909
Random Number 2: 1684909
Random Number 3: 1684909
Random Number 4: 1684909
any idea what is wrong with my code?
Thanks...
regards,
vic
|
|
|
|
|
Simple. Your creating a new Random number generator with each invocation of .GetID() and in creating that generator, your seeding the RNG with the current time, in Ticks. What your doing is telling the new random number generator to start with the seed value and generate a REPRODUCABLE string of numbers. What you should be doing in your IDGenerator class is declaring a class level Random , initializing it once, and using it's .Next method on each call to .GetID() .
public class IDGenerator
{
int min, max;
Random r = new Random(unchecked((int)DateTime.Now.Ticks));
public IDGenerator ()
{
this.min = 1000000;
this.max = 9999999;
}
public string GetID ()
{
String myNumber = r.Next(min,max).ToString("0000000");
return myNumber;
}
}
Also, random numbers are not guaranteed to be unique during the life of the generator, so review your policies on what this function will acceptibly return. It's entirely possible that it could return the same number twice (or more) in a row.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The following works for me:
int min = 1000000, max = 9999999;
Random r = new Random();
for(int i = 0; i < 5; i++)
{
Console.WriteLine(r.Next(min, max));
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
I need to know how to keep the navigation in the same window using the WebBrowser Control. It's NewWindow event does not have the URL in it. I read about SHDocVw.WebBrowser_V1, interface, which has a better NewWindow event, but I don't know how to make the cast from the WebBrowser control in C#. I've noticed that the msdn article on this is in VB. Thanks.
|
|
|
|
|
|
I’m having trouble finding a clear answer to my question regarding visual inheritance and MDI children. I have made several dialog style forms/apps which were derived from a master template form (dll) – that works great, but I want to take it a step further. My next step was to create a MDI style application using visual inheritance for each child window. Just for information - I’m writing this in VS ver7 (C# base).
So, some questions:
1. Can I make a MDI application into which each child is a based on a master “template” form (dll). My hope is that each child would be its own DLL – easing future modifications and upgrades. Can this be done with .net’s virtual inheritance?
2. If this is possible, is there a way I can dynamically add new children DLL’s (which are visually derived from a master template form) to the MDI application without recompiling the base MDI application (that would be my dream)? Each new child would add new functionality to the core application – but maintain the same base “look”. Obviously this would take some coding, but is this possible?
If you have some ideas, experience, or know of any examples to either of my questions – please feel free to share your ideas.
|
|
|
|
|
rolst5 wrote:
Can this be done with .net’s virtual inheritance?
Do you mean visual inheritence? Yes, it can.
MDI child forms are just that - Form derivatives. So, you can extend the Form class with your own then extend that "template" with other classes. Make sure that any members - including controls - are protected if you want to modify them in derivative classes. These can be in separate assemblies as well, but the assembly that contains the base class must first be compiled before Visual Studio will let you extend it through the visual inheritence wizard.
Also, you cannot have circular references in Visual Studio (it's possible on the command line, but a pain), so define your base class in a separate assembly (project) apart from your main application that defines the MDI parent form.
If you want to dynamically reference assemblies that contain different types of MDI child forms, there's a vast number of articles on this site regarding plug-ins. Just search for "plug-ins". There's a great many ways of locating plug-ins from enumerating files in a particular directory to loading well-defined types from the application's .config file.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I am trying to start Excel through code. My objective is to start excel and load a Addin called TM1. If i go in through explorer and click on this Addin(.xla) it connects to a datawarehouse and adds a menu item in excel called Tm1.
Well here is the code that I am using to accomplish the above tasks:
try
{
//create a new excel app.
_newApp = new Excel.Application();
_newApp.Visible = true;
_newApp.AddIns.Add("C:\\Applix\\Integra\\bin\\tm1p.xla","C:\\Applix\\Integra\\bin\\tm1.xla");
_userBook = (Excel._Workbook)_newApp.Workbooks.Add("C:\\Inetpub\\wwwroot\\ExcelAddinExample\\ExcelTemplates\\01_fsTemplate_orig.xls");
_tm1Book = _newApp.Workbooks.Open("C:\\Applix\\Integra\\bin\\tm1.xla",0,false,5,"","",true,
Excel.XlPlatform.xlWindows,"\t",false,false,0,false,null,null);
//try to call the copnnect routine;
_newApp.Run("N_Connect","toad","bisu","GBA03",null,null,null,null,null,null
,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null);
}
Well my code is failing at the Addins.Add() line. What am i doing wrong.
Thanks for any help.
|
|
|
|
|
sameerhanda wrote:
Well my code is failing at the Addins.Add() line. What am i doing wrong.
That's not very helpful. What exception is thrown? What does the exception message state? What's the stack trace of the exception? Specific information like this is necessary to diagnose the great majority of problems. Always give as much information as possible regarding the problem.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
The exception thrown by this piece of code is excatly what I said in my previous post:
{"Add method of AddIns class failed" }
and unfortualty the stack trace is not very descriptive either. But here it is:
" at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)\r\n at Excel.AddIns.Add(String Filename, Object CopyFile)\r\n at ExcelModel.ExcelHandler.CreateExcel() in c:\\sameer work area\\excelmodel\\excelhandler.cs:line 32"
I copied this directly from the debugger.
Anyway hope this gives you a better idea.
|
|
|
|
|
sameerhanda wrote:
{"Add method of AddIns class failed" }
That's not an exception. That's the exception text. What was the exact exception type thrown (ex: TargetInvocationException ).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
What was the exact exception type thrown (ex: TargetInvocationException).
Sorry about that..
The excat exception type is ..
{"System.Runtime.InteropServices.COMException"}
Sameer
|
|
|
|
|
Since it's a COMException , the the first thing you should do is suspect the COM server you're calling and look at the documentation.
Having done that, I see two flaws:- The second parameter is ignored if the
Filename refers to a local file (on the hard disk), and CopyFile is a variant of type VT_BOOL (bool ), so even if you had to specify it (i.e., Filename refers to a file on a network share, for example) you need to cast it to an object which gets marshaled as a VARIANT (native type):
object copyFile = true;
excelApp.AddIns.Add("filename", copyFile); You don't need to specify the second parameter, however, if you always know the file will be on hard disk. If you know this assumption is safe, then use object copyFile = Missing.Value; instead of assigning a bool .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Just wanted to give you a FYI as to how I had fixed this problem..or gotten around it.
int _count = _newApp.AddIns.Count;
for( int i = 1;i < _count ; i ++ )
{
//test to see what is the name of the AddIn.
if( _newApp.AddIns[i].Name.StartsWith("tm1p"))
{
//test to see if it is installed
if ( !_newApp.AddIns[i].Installed )
{
_newApp.AddIns[i].Installed = true;
this._addinIndex = i;
}
}
}
However I will try your method to Heath. Thank's for your responses.
|
|
|
|
|
i'm developing a chat application which allows the user to put smilies in the text box. how can i do this? are there any sample codes? thank you for helping me.
|
|
|
|
|
If you want to display anything more than text, the TextBox is a bad class to extend since it encapsulates the Edit Windows common control and is pretty inflexible. In these cases, most use the RichTextBox , for which you can find many articles about using with chat applications if you search this site or google[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Tell me any five real time web application developed in C# & Asp.Net or Vb.Net & Asp.Net combinations and which have more than 20000 thousands of hits per hour. .
Sreejith Nair
|
|
|
|
|
Sure. www.microsoft.com, www.yahoo.com, www.google.com, www.cnn.com, www.espn.com, ...
All have content that is updated and served real-time.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hoooo, You mean to say these are developed using dotnet
Sreejith Nair
|
|
|
|
|
Not in their entirety. Even Microsoft.com isn't done completely in ASP.NET and C#/VB.NET. There are many different technologies that go into these and most other commercial sites, like Java, PHP, plain old HTML, CSS, XML, CGI, C/C++, ... C#/VB.NET and ASP.NET are just a smallish part of the greater whole.
Besides, 20,000 hits per hour is only 5 hits per second. You could handle that with a single processor box @ 1GHz...
Microsoft.com averaged about 1,600,000 hits in an hour, or 1,121 hits per second, for the month of May 2004. Check out Inside Microsoft.com[^] for hint at what it takes to support one of the worlds busiest web sites.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
And soon that'll double with all the hits on my new blog at http://blogs.msdn.com/heaths[^]!
Much of it is actually ASP.NET now, but not the stock "stuff". Much of it is custom page handlers. We also use SharePoint a lot, which is built on ASP.NET (well, at least SharePoint Service 2.0). There's still some ASP running around, but slowly things are being upgraded to ASP.NET. There have been some MSDN articles and MSDN TV episodes discussing these transitions if you're interested.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hey all,
I'm trying to adapt our application to work with large fonts- that is when someone goes to display properties, appearances, and changes font size to large or extra large, have my application have larger font sizes. The basic change I've made which works fine is to put in the constructor of the main application the code:
this.Font = new Font(this.Font.FontFamily, SystemInformation.MenuFont.SizeInPoints, this.Font.Style, this.Font.Unit, this.Font.GdiCharSet, this.Font.GdiVerticalFont);
SizeF sf = Form.GetAutoScaleSize (this.Font);
this.AutoScaleBaseSize = sf.ToSize ();
this.AutoScale = true;
I had some trouble just changing the fontsize, that's why I've got that more complicated call (which may not be entirely necessary). Anyway, that works. The problem is that for some reason, in some of my internal controls (but not all! that's the thing) textboxes are getting wider- stretching to the right. This is causing problems like the textboxes covering up buttons that are next to them, etc. I can't figure out for the life of me why they're getting wider- and I can't figure out why only on some controls they are. For example, on one form they're stretching as far as the panel lets them.
I thought it might be the AutoSize property, but even with that off, they still do it (the AutoSize property, as it turns out, only resizes the height based on font size). I coded something that just reverses the change, but there should just be a way to tell the textbox not to resize automatically like it is doing. I checked all over my code and there's nothing I do to change the width. In fact, when I tried to put the code to reverse the automatic change in the Layout event rather than the Resize event, it works, but then when I minimize and maximize, the textboxes stretch again, so it really does see like something built in. Does anyone have any clue as to what might be causing this and how to turn it off?
-David
|
|
|
|
|
|