|
I just checked and the above solution will indeed work. However, that is quite a bit of extra work (you have to create an interface, then create a wrapper class).
Instead of that, why not just make your function accept an IList instead of a Control? For instance,
public void function(IList items)
{
items.Clear();
}
Then pass the items to it like:
ComboBox combo = new ComboBox();
ListBox listBox = new ListBox();
function(combo.Items);
function(listBox.Items);
That is an easier solution and will work equally well. If your function requires the Control, not just the .Items, then you should use the first solution I posted.
The graveyards are filled with indispensible men.
|
|
|
|
|
Hi Judah,
Thanks for your input. I'll try it out and see if that's what I need.
|
|
|
|
|
Both Listbox and ComboBox inherit from ListControl , so it would be somewhat logical to assume that's where the Items porperty comes from. If only it were that easy.
Although they share a common name, Items properties represent differents type of objects in Listbox and ComboBox (ListBox.ObjectCollection and ComboBox.ObjectCollection , respectively).
Therefore, there's no common ancestor you can cast to and call Items.Clear() .
As for your question of how to create a generic solution, there is a way, although it may be overkill for what you're looking for.
using System.Reflection;
object collection = ctrl.GetType().GetProperty("Items").GetValue(ctrl, null);
collection.GetType().GetMethod("Clear").Invoke(collection, null); Alas, the 'generic' solution is usually not the easiest
Charlie
if(!curlies){ return; }
|
|
|
|
|
Oops. Upon further reflection (no pun intended) and reading the other proposed solution, I realized that once
you've got your object collection, you can cast is to IList and call
Clear() on it. So the second line would become:
object collection = ctrl.GetType().GetProperty("Items").GetValue(ctrl, null);
((IList)collection).Clear();
Charlie
if(!curlies){ return; }
|
|
|
|
|
Hi Charlie,
This was what I was looking for!
Thanks a lot.
John
|
|
|
|
|
Hi,
I have a web app where I'm using SmtpMail to send individual messages when a request is made to a supervisor. It works ok, but the problem is that the web server is not the smtp server and relaying through the mail server (Lotus Domino 5) takes like , I'm not kidding, 4 - 5 seconds to execute the Send method! If I use the local IIS smtp server, and have it relay to the real mail server, the call happens instantly. I've tried pointing at another IIS smtp server on out network and again, it enters and leaves Send immediately. So my question is, what is Send doing with the Domino server that is taking so long? Has anyone had any experience with this?
|
|
|
|
|
Have you tried sending an e-mail with outlook though you Domino server to see how quick it is?
It could just be your setup.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Hi, I have a problem. On our computer (Celeron 566 MHz, 128MByte, W2000, .NET1.1) we use a CAN bus for getting measurement data from a client. For the CAN bus there is a DLL for NT/2000. Everytime if data comes in, the DLL calls a callback routine in my C# program. Data will come all 50 ms at the moment. This is working so far but if the data comes in, the CPU usage goes up to 100%, even if the callback routine in my C# program is doing nothing. That means only for calling the callback routine every 50 ms is killing the system. Is it possible that I'm doing something wrong?
Before we have written this software in Delphi and at that time the program needs only around 2%-5% CPU usage with 50 ms and around 10% with 1 ms data interval.
Regards
Michael
|
|
|
|
|
I think you'll need to post a little more information to get much help. That's a pretty difficult question to answer without code. Still, when you say CAN, are you referring to the bus protocol often used in automobiles, trucks, and various equipment? If so, who wrote your communications DLL? If it's what I'm thinking, you need to take a look at setting filters to limit the amount of incomming data. CAN data running at full speed (about 1 meg I think) is quite a bit of callbacks. If filtering isn't an option in the supplied DLL, you could write your own in ATL COM. This should be much faster and then you could post up only the messages you really need to your application. If we're on the same page, you may want to consider another provider for your communications DLL like possibly Noregon Systems out of Winston Salem, NC.
|
|
|
|
|
Ok, I will give some more info. CAN means the busprotocol which is used in automotiv industries. The DLL is written by the manufacturer of the industrial computer (using the Win DDK), where the CAN chip is build in.Of cause this is not only the DLL but also a system driver for this hardware. The DLL is only the interface. We used the CANbus with 250 kBaud which enables us to read the incomming Data with 1 ms resolution and we need all the data because we have to control a very dynamical process.
Next I will give some code how I have impleneted this:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;
using System.Security;
namespace CanOpen
{
// First of all I define the data structure for the callback function
// Before this was public byte oldData[] and public byte newData[]
// But the structure of the Callback function works with byte oldData[8] and
// byte newData[8] and I didn't know how to realize this in C#
public struct NewDataType
{
public int node;
public byte oldData1,
oldData2,
oldData3,
oldData4,
oldData5,
oldData6,
oldData7,
oldData8; //
public byte newData1,
newData2,
newData3,
newData4,
newData5,
newData6,
newData7,
newData8; //;
public int dataLen; //max. 8 bytes (= max. PDO data length)
public PDOChannelType PDOChannel;
}
.....
// Next I define the delegate for the Calback function
delegate void DelegateUserCANNewInputData( ref NewDataType pNewData);
.....
// This is the function, which registers the callback function,
// I tried with and without SuppressUnmanagedCodeSecurity but it has no influence
[DllImport("canopen.dll"),SuppressUnmanagedCodeSecurity]
static extern int CANopenNewInputDataRegister(DelegateUserCANNewInputData
UserCANNewInputData);
.....
private void RegisterCallBackFunctions()
{
int RetCode;
DelegateUserCANNewInputData FptrUserCANNewInputData = new DelegateUserCANNewInputData
(UserCANNewInputData);
RetCode = CANopenNewInputDataRegister(FptrUserCANNewInputData);
}
|
|
|
|
|
Ok, I will give some more info. CAN means the busprotocol which is used in automotiv industries. The DLL is written by the manufacturer of the industrial computer (using the Win DDK), where the CAN chip is build in.Of cause this is not only the DLL but also a system driver for this hardware. The DLL is only the interface. We used the CANbus with 250 kBaud which enables us to read the incomming Data (PDOs) with 1 ms resolution and we need all the data because we have to control a very dynamical process.
Next I will give some code how I have impleneted this:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;
using System.Security;
namespace CanOpen
{
// First of all I define the data structur for the callback function
// Before this was public byte oldData[] and public byte newData[]
// But the structure of the Callback function works with byte oldData[8] and
// byte newData[8] and I didn't know how to realize this in C#
public struct NewDataType
{
public int node;
public byte oldData1,
oldData2,
oldData3,
oldData4,
oldData5,
oldData6,
oldData7,
oldData8; //
public byte newData1,
newData2,
newData3,
newData4,
newData5,
newData6,
newData7,
newData8; //;
public int dataLen; //max. 8 bytes (= max. PDO data length)
public PDOChannelType PDOChannel;
}
public class VCanOpen
{
.....
// Next I define the delegate for the Callback function
delegate void DelegateUserCANNewInputData( ref NewDataType pNewData);
.....
// This is the function, which registers the callback function,
// I tried with and without SuppressUnmanagedCodeSecurity but it has no influence
[DllImport("canopen.dll"),SuppressUnmanagedCodeSecurity]
static extern int CANopenNewInputDataRegister(DelegateUserCANNewInputData
UserCANNewInputData);
.....
// During the initialization of the CANOpen class
private void RegisterCallBackFunctions()
{
int RetCode;
DelegateUserCANNewInputData FptrUserCANNewInputData = new DelegateUserCANNewInputData
(UserCANNewInputData);
RetCode = CANopenNewInputDataRegister(FptrUserCANNewInputData);
}
.....
// This is the callback function which will be called by the DLL
void UserCANNewInputData(ref NewDataType pNewData)
{
// Do something or nothing
}
....
} // class VCanOpen
} // namespace CanOpen
Regards
Michael
|
|
|
|
|
Matt is right, do you really need all of that data? Are you using RP1210A? If so, filter out what you don't need at the driver/dll layer and don't allow all of the data to come up. CAN is a very fast protocol and on a loaded bus can bring almost any computer to its knees if it tries to process every message.
david
|
|
|
|
|
I really need all this data. I need all the PDOs coming in for this measurement data. The data is already filtered in the system driver. And there is only one other node which sends data. At the end I need to record the data with a frequncy of 1 kHz. But even with 50 ms the system is not more usable. Again, before we use Delphi and it works very well. Only 5 % of CPU is used with Delphi.
Another question? If it is so, as you described, maybe .NET is not the future solution for applications which must handle a big amount of data in short time.
regards,
Michael
|
|
|
|
|
Couple of thoughts:
1) Try using windows messaging instead of callbacks. Windows messaging is much more efficient and optimized by the OS.
2) Try offloading the callback to another thread.
As for Delphi, I've never used it.
What is your busload on the CAN network you're trying to read everything from and what speed are you running (250, 500, 1M, etc)? I can tell you that nearing 70-100% busload on a 250k CAN network will make a boat anchor out of my PC, if it tries to process all the data. Not to mention you are trying to record it... which requires flushing to a file every now and then.
David
|
|
|
|
|
In the area of raw ability to crunch numbers, how does .NET technology compare with old fashioned C++? So for example if I wanted to render a fractal would CLR do that well? The reson is that .NET will lend itself perfectly to user customisation of modules in my graphics program because I can have it recompile after the user has edited the code, allowing huge flexibility. But is .net up to the task?
Joel Holdsworth
|
|
|
|
|
|
|
I used an ActiveX Object in my VB6 project like this:
obj = CreateObject("AAA.BBB");
When I tried to do the same thing in C# .Net project, I can't not find this object in "Add reference" dialog.
Does anyone know why?
Thanks in advance!
|
|
|
|
|
Assuming you already looked under the "COM" tab of the add reference dialog box, the Component name used when creating a late bound control in VB6 using CreateObject often differs from the name displayed in the add reference dialog box. As an example, to create an Excel application reference in VB6, you could do this:
xl = CreateObject("Excel.Application")
but when you look in the VS.NET add reference dialog box, it is described as the "Microsoft Excel 9.0 Object Library".
What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
|
|
|
|
|
Hi guys,
Have been handed a job to do from down on high....my company are looking at using ASP.NET for some new modules in an existing ASP classic application.
My boss is concerned with the end-user issues connected with .NET - not the benefits, but the sort of SysAdmin problems that installing the framework might create, such as existing apps not working etc....
Can anybody share their experiences, or point me to some resources on the subject?
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
As far as the clients are concerned there should be no issues (just as there are no issues if you point your browser to a page that ends with a .aspx extension). You only have to be concerned with the server machines that are hosting ASP.NET, which must of course have .NET installed on them.
Kevin
|
|
|
|
|
Classic ASP can co-exist peacefully with ASP.NET on the same machine, provided, of course, that the machine meets all the other requirements to run the .NET framework and ASP.NET.
That being said, there are potential issues if you try to integrate ASP and ASP.NET together, since they don't share session state, application state and so on. There are articles on how to make them work together if you look around.
What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
|
|
|
|
|
But, isn't there some issues with passing Application/Session variables from ASP applications to ASP.NET applications.
Norman Fung
|
|
|
|
|
Yes, as I mentioned, "there are potential issues if you try to integrate ASP and ASP.NET together, since they don't share session state, application state... "
That can be overcome, to an extent, by not relying on Application and Session if you have to put the two together. One could use query strings, hidden forms, etc. It's more work, but it might be a way to gradually transition an app from Classic to .NET.
What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
|
|
|
|
|
We are currently scoping a new (smallish) project, and need to make decision as to whether we develop it in .Net or C++.
Does anyone know of any statistics that detail the distribution of the .Net framework on desktop systems?
|
|
|
|
|