|
at the IL level a property "xyz" gets compiled as a get_xyz() or set_xyz() method. the JIT compiler might inline that, I don't know if it does so.
|
|
|
|
|
It should, since the body of the method will be smaller than 16 bytes
|
|
|
|
|
there are lots of things a compiler should do.
In my experience comparing actual behavior with a published list of features and qualities tends to be very disappointing.
|
|
|
|
|
True
|
|
|
|
|
What is the difference in critical section, Mutex and Semaphore ?
When we use Mutex and when Semaphore ?
|
|
|
|
|
This is not a homework forum, but I'll be nice today...
A critical section is a piece of code which is not multithreading safe. It may not be interrupted.
You use a Mutex to reserve a ressource that can be used by exactly one thread at a time.
You use a Semaphore to reserve a ressource that can be used by a finite count of threads at a time.
Now, get back to your books or Wikipedia.
This statement is false.
|
|
|
|
|
Hi
Im new to C# and serial programming.
I need to write a program which monitors the serial port.
i need help to
i need to check whether a port is used by any other application , and display the results???
any help would be greatly appreciated.
Ani
|
|
|
|
|
Hi,
you should learn C# before trying serial interface programming, as that isn't a very simple matter.
you can get the names of all existing ports through SerialPort.GetPortNames().
you can test a port for availability by creating an instance with new SerialPort(portname).
There is MSDN documentation on the SerialPort class (as for all others) that would explain it.
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
{
addItem();
}
private void addItem() {
String [] ports = SerialPort.GetPortNames();
comboBox1.Items.AddRange(ports);
}
private void button1_Click(object sender, EventArgs e)
{
String pName = comboBox1.Text;
// MessageBox.Show(pName);
SerialPort sp = new SerialPort(pName);
/*if (sp.IsOpen)
{
MessageBox.Show("port is already opened");
}
else
{
MessageBox.Show("port is available");
sp.Open();
}
**/
try
{
sp.Open();
}
catch(Exception ee)
{
label3.Text = "the port is not available";
// MessageBox.Show( "the port is not available");
}
}
Hi thanx for your reply.
i wrote this code, but i dont want to open the port, i want to check whther the port is available. when i do the isopen check it says the port is not opened, but im connected through hyper terminal.
|
|
|
|
|
Are you actually connected to the port with Hyper Terminal, or do you just have the program running with the port selected? HT may not set the Open property on the port until you make a live connection with a remote device, and the port would continue to be available until that happens. Try opening the port with your program, then making a connection with Hyper Terminal using the same port. HT should give you an error message if your program has successfully opened the port.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
hi thnx for the help
i resolved the prob
|
|
|
|
|
aniarun wrote: i resolved the prob
Care to share the secret? I might need to use the Serial class one of these days.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
hi
i am not sure whther this the correct solution. but for now prob is solved i used wmi properties to solve
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_SerialPort");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_SerialPort instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("StatusInfo: {0}", queryObj["StatusInfo"]);
Console.WriteLine("port name {0}", queryObj["DeviceId"]);
int i= Convert.ToInt32(queryObj["statusInfo"]);
if (i==3)
{
Console.WriteLine("port is available");
}
else {
Console.WriteLine("port is not available");
}
}
i wrote all the properties to an text file and compared the values when the port was open and closed
/*foreach (PropertyData prop in queryObj.Properties)
{
Console.WriteLine("{0} - \t {1}\n", prop.Name, prop.Value);
tw.WriteLine("{0} - {1}", prop.Name, prop.Value);
}**/
//tw.Close();
statusinfo had value 3 when the port was opened , thts wht maed me use that as the conditional case.
any1 has better solution for this???
|
|
|
|
|
Although I think there ought to be a simpler solution, yours is brilliant. It's a bit like hunting rats with an AK-47, but it works. It has long amazed me that Microsoft has always made it so hard to access ports, yet Java has included well documented port management functions almost since its inception. I guess that's due to the difference in target audiences, Java being meant to control devices, and Windows to run general purpose machines. Oh, well... Good work!
I hope we'll see an article posted here when you're done.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
ya
mine is kind of too complicated, im still trying to find a better way lol :P
now i need to find the application which is using the port i will have to find another way from scratch
please tell me suggestions if u guys have any idea about that
|
|
|
|
|
anyone have any idea of how to find the process/appliaction, which is using the port
|
|
|
|
|
Hey I m new in programming and I've spend 3 month on c# and now want to participate in imagine Cup with my team. and Looking for topic and the first requirement of imagine cup is:
Your entry must address a social cause connected to the 2010 Theme: "Imagine a world where technology helps solve the toughest problems".
other information are here: link
can any body help me to decide topic for software??
Thank You!
|
|
|
|
|
mwaqas1990 wrote: can any body help me to decide topic for software?
You are entering this competition so you need to do the thinking and the work, so that if you win you don't have to share your prize with the
6,684,061 members of CodeProject.
|
|
|
|
|
Thank You so much! i have so many different ideas and i am working on it thank you!
|
|
|
|
|
Hi,
I am attempting to create a simple region growing image program. The idea is that these regions will become "nodes" for the next part of my project. I just need a bit of advice of a good easy way to store the pixel data.
At the moment I have a Class called PixelData that holds x/y location, pixel color value and a Label ("F"- free/ "A"-allocated etc) of all the pixels in a grayscale image. This is all held by a List<PixelData>. I have a node class that will hold the pixels that it consumes.
So the idea is that a random seed point will be selected, and that the PixelData list will change that pixel lable to "A" for allocated and also add it to the node class. Over time lots of pixels in the PixelData list will become Allocated by the node, and the node class's list of pixels will grow.
This is the first way that came to me. Can anyone recommend a better or simpler way? Speed isnt a necessity at this stage, I just want to get something working.
Regards.
|
|
|
|
|
Sorry, but I don't understand what you're trying to accomplish, so I can't really offer any ideas.
If you want to choose a pixel at random and change its attribute, then just do it -- that should be easy. The question for me would be : Why? Certainly that's not the entire object of the program or class?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Hi,
if I understand you correctly you have an object per pixel, holding grayscale, x, y, and some state. That is a lot of data, and a sure way to spend lots of memory and time. .NET will need some 32 bytes per object, so a megapixel image of yours will consume some 40MB of memory of which 80% is irrelevant to your app (I'm assuming shorts for grayscale, x, y, state). These pixel objects will be spread around in your app's memory, and the garbage collector will eventually have to watch over them and collect them when no longer needed; that will take some doing.
So I am completely against the idea of turning every pixel into an object.
I also am not sure why a pixel needs to store its location, I've never done that.
I tend to keep monochrome pixels in a one-dimensional array, so I can easily move to its neighbours (by adding +1, -1, +WIDTH, or -WIDTH to the array index, or pointer). A second array could keep the state. That would result in only 4 bytes/pixel, one tenth of the pixel=object approach; and pixels would be adjacent in memory making your app take full advantage of the processor caches.
Another tip is this: having state, you could make the arrays a bit larger, effectively adding a boarder to the image, then store a special value in the state array for those border "pixels". That may be sufficient to avoid all border tests, as you now can move from a pixel to its neighbour, and from an edge pixel to a border pixel, without falling of the image.
modified on Monday, December 14, 2009 6:45 PM
|
|
|
|
|
This is my code:
using System;
using System.IO;
using System.ServiceProcess;
using System.ComponentModel;
using System.Configuration;
using System.Configuration.Install;
namespace ServiceTest
{
public class MainClass : ServiceBase
{
public static void Main(string[] args)
{
ServiceBase.Run(new MainClass());
}
protected override void OnStart(string[] args)
{
Console.WriteLine ("Started OK");
base.OnStart (args);
}
protected override void OnStop ()
{
Console.WriteLine ("Stoppeds OK");
base.OnStop ();
}
}
[RunInstaller(true)]
public class MainClassInstaller : Installer
{
public MainClassInstaller()
{
ServiceProcessInstaller process = new ServiceProcessInstaller();
process.Account = ServiceAccount.LocalSystem;
ServiceInstaller serviceAdmin = new ServiceInstaller();
serviceAdmin.StartType = ServiceStartMode.Manual;
serviceAdmin.ServiceName = "Service Test";
serviceAdmin.DisplayName = "Service Test";
Installers.Add(process);
Installers.Add(serviceAdmin);
}
}
}
I'm writing a Server program in Monodevelop on Ubuntu 9.04, and I've got mono-service2 installed. When I try and run the exe via mono-service2 --debug ./ServiceTest.exe I don't get any output.
modified on Monday, December 14, 2009 4:51 PM
|
|
|
|
|
Try to use:
Console.Out or Console.Err
|
|
|
|
|