|
I have finished an application which uses .net. I created an installer and works fine but on some machines somethings don't behave, for example, I have a DataGridView with a button column and when pressed should open a form but on some machines it does not do anything. All machines have xp. I guess it could be .net framework.
How do I find what framework my app depends on? How do I find if it requires a certain fix like .net framework 1.1 hotfix?
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
If there is a missing depenency you should get an exception when your app tries to run the missing code. If you are swallowing exceptions then don't it is probably hiding the reason for your error.
If you can add logging to the area where the form should open then that may help.
|
|
|
|
|
I've built an InfoPath form that queries WMI data and displays it in the form so that we can submit the info to a SharePoint list.
I'm putting on the final touches and am having problems with one small section. When i query the RAM, i have it display the information into a repeating table. The problem is when i create the repeating table for some reason it duplicates the first row. I found an article on how to remove the first row (http://www.bizsupportonline.net/infopath2007/programmatically-delete-first-row-repeating-table-infopath.htm)
I use this same bit of code to remove the first row from another section and it works just fine, but for some reason when i do this very same thing it deletes the first 2 rows. I can't figure out why it works fine in one section but not in the other section, i copied and pasted the same bit of code so it should work the same. If someone could help me figure out what's going on here i'd appreciate it.
code sample:
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System.Management;
using System.Net.NetworkInformation;
namespace Inventory_Rev1
{
public partial class FormCode
{
ManagementObjectSearcher searcherMemory =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PhysicalMemory");
public void InternalStartup()
{
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
foreach (ManagementObject queryObj in searcherMemory.Get())
{
int counter = 1;
{
string slot = queryObj["DeviceLocator"].ToString();
string capacity = queryObj["Capacity"].ToString();
string speed = queryObj["Speed"].ToString();
XPathNavigator xnMyForm = this.CreateNavigator();
XmlNamespaceManager ns = this.NamespaceManager;
xnMyForm.SelectSingleNode("/my:myFields/my:Memory/my:Ram/my:slot", ns)
.SetValue(slot);
xnMyForm.SelectSingleNode("/my:myFields/my:Memory/my:Ram/my:capacity", ns)
.SetValue(capacity);
xnMyForm.SelectSingleNode("/my:myFields/my:Memory/my:Ram/my:speed", ns)
.SetValue(speed);
counter++;
AddItemMemory(slot, capacity, speed);
DeleteFirstEmptyItemMemory();
}
}
}
private void AddItemMemory(string slot, string capacity, string speed)
{
XmlDocument doc = new XmlDocument();
XmlNode group = doc.CreateElement("Ram",
NamespaceManager.LookupNamespace("my"));
XmlNode field = doc.CreateElement("slot",
NamespaceManager.LookupNamespace("my"));
XmlNode node = group.AppendChild(field);
node.InnerText = slot;
field = doc.CreateElement("capacity",
NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = capacity;
field = doc.CreateElement("speed",
NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = speed;
doc.AppendChild(group);
MainDataSource.CreateNavigator().SelectSingleNode(
"/my:myFields/my:Memory",
NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());
}
private void DeleteFirstEmptyItemMemory()
{
XPathNavigator domNav = MainDataSource.CreateNavigator();
XPathNavigator itemNav = domNav.SelectSingleNode(
"/my:myFields/my:Memory/my:Ram[1]",
NamespaceManager);
if (itemNav != null)
itemNav.DeleteSelf();
}
}
}
|
|
|
|
|
Hi all,
I've been searching high,low, and in between for a solution to my current problem & thought I'd post here to see if anyone here has tackled this one before.
I'm using VS2008, C#, & .Net3.5 SP1.
I have a USB based COM port attached to a GPS device, and I'm testing what happens when you unplug the USB cable while the SerialPort connection is open. The results are an unhandled exception & a program crash that occurs when the SerialPort.BaseStream is garbage collected, according to the callstack when the exception occurs..
The problem is discussed a bit @ this link[^], which includes this sample to reproduce:
using System;
using System.IO.Ports;
namespace SerialPortUsbCrash {
class Program {
static void Main(string[] args) {
SerialPort serialPort = null;
serialPort = new SerialPort("COM12", 19200, Parity.None, 8,
StopBits.One);
serialPort.Open();
Console.Write("Pull out the USB cable, and push return");
Console.ReadLine();
try {
serialPort.Close();
} catch (Exception ex) {
Console.WriteLine("Got exception closing SerialPort: " + ex);
}
Console.WriteLine("- THE END -");
Console.ReadLine();
}
}
I've tried a number of suggestions based on google searches, including app.config change, closing/disposing SerialPort on WM_DEVICECHANGE, GC.SuppressFinalization(serialPort.BaseStream) on device removal & others, but they don't resolve the issue.
Anybody here figure this one out?
Thanks.
|
|
|
|
|
I have no experience with SerialPort . However is it possible to
using (serialPort = new SerialPort("COM12", 19200, Parity.None, 8, StopBits.One))
{
serialPort.Open();
Console.Write("Pull out the USB cable, and push return");
Console.ReadLine();
try {
serialPort.Close();
} catch (Exception ex) {
Console.WriteLine("Got exception closing SerialPort: " + ex);
}
Console.WriteLine("- THE END -");
Console.ReadLine();
}
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for the reply!
If I use using(...), like you suggest, and the COM port is removed, what will happen is that the exception will occur sooner rather than later, as it'll happen not too long after the call to Dispose() occurs. Using using() just speeds that up a bit..
|
|
|
|
|
Oh well.
I hope someone with actual knowledge is able to help you out.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
This particular problem may not be handleable (is that a word?).
As you know all USB devices should be remved 'safely'. When a device removal is done properly a DBT_DEVICEQUERYREMOVE[^] message is broadcast which you can catch and close the port first.
If a user decides to just unplug a USB device - they shouldn't expect programs that use them not to explode!
This article[^] may be of interest.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: they shouldn't expect programs that use them not to explode
I disagree. Should a program explode when a disk stops working, when a network goes down, when the serial cable gets unplugged?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
DaveyM69 wrote: If a user decides to just unplug a USB device - they shouldn't expect programs that use them not to explode!
I agree with Luc. If someone yanks the cable then the program should always try to gracefully handle the exception.
|
|
|
|
|
I did watch for WM_DEVICEREMOVE and at the point in time where I handle DBT_DEVICEREMOVECOMPLETE, SerialPort.IsOpen already == false, and closing it doesn't make a difference.
I checked, there is no DBT_DEVICEQUERYREMOVE or DBT_DEVICEREMOVEPENDING event, just DBT_DEVICEREMOVECOMPLETE when the port is already closed...
|
|
|
|
|
Just in case you are not watching your thread, DaveyM69 has made a reply, but attached it to my first answer by mistake.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Oops!
Thanks Henry
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Okay, I've been trying to figure this out for the last 24 hours to no avail.
I'm writing a datebook style program just as a personal test while I learn, and I've run into a snag. The idea is that the user enters a date and event, then presses a 'save event' button which is supposed to both write the event to the event list window, and append it to a file called datebook.txt. My problem is that each time the 'save event' button is pressed, it rewrites the entire datebook.txt file. How do I fix this? I'm including the code below, minus irrelevant things (such as empty textChanged sections, etc).
Thanks.
namespace WpfApplication2
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
DateTime current = DateTime.Now;
Entrance();
}
private void Entrance()
{
selectedDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
}
private void displayEvents_Click(object sender, RoutedEventArgs e)
{
try
{
DateTime selected = DateTime.Parse(enteredDate.Text);
selectedDate.Text = selected.ToString("MM/dd/yyyy");
}
catch (FormatException)
{
MessageBox.Show("The date you enterd was invalid.\n\nPlease reenter the date in
the format MM/dd/yyyy.");
}
}
private void saveNewEvent_Click(object sender, RoutedEventArgs e)
{
try
{
WriteToFile();
WriteToEventList();
}
catch (FormatException)
{
MessageBox.Show("The date you enterd was invalid.\n\nPlease reenter the date in the format MM/dd/yyyy.");
}
}
private void WriteToFile()
{
DateTime newEntry = DateTime.Parse(newDate.Text);
string addEvent = "";
addEvent = newEvent.Text;
using (TextWriter writeEvent = new StreamWriter("datebook.txt"))
{
writeEvent.WriteLine(newEntry.ToString());
writeEvent.WriteLine(addEvent);
}
}
private void WriteToEventList()
{
DateTime newEntry = DateTime.Parse(newDate.Text);
string addEvent = "";
addEvent = newEvent.Text;
eventsList.AppendText(String.Format("{0}\t{1}\n", newEntry, addEvent));
}
}
}
|
|
|
|
|
Try to use the method Flush() - streamWriter's name.Flush();
|
|
|
|
|
It figures, I happened to be looking for something else and found at least one solution that works. Switching the entire TextWriter writevent line for StreamWriter writeEvent = File.AppendText("datebook.txt") . Now i just need to figure out how to format it with a tab between the date and event instead of a line return...
Previous reply:I appreciate the quick response, but I don't fully understand...
Having no idea what the Flush() method does exactly, I googled it, and from what I've found this is merely an alternate way of closing the stream to ensure the data is purged. How would that help in this case, as the new event is being written, it's just being written over the previous event, so only the most recent saved event is in the text file when I open it.
Thanks again
modified on Wednesday, March 25, 2009 4:30 PM
|
|
|
|
|
Perhaps changing your WriteToFile method to the following will help:
private void WriteToFile()
{
DateTime newEntry = DateTime.Parse(newDate.Text);
string addEvent = "";
addEvent = newEvent.Text;
using (TextWriter writeEvent = System.IO.File.AppendText("datebook.txt"))
{
writeEvent.WriteLine(newEntry.ToString());
writeEvent.WriteLine(addEvent);
}
}
This should append text to the file. I'm not sure how it will handle the file not being present, so you may want to test for that.
|
|
|
|
|
using (TextWriter writeEvent = new StreamWriter("datebook.txt", true))
The second argument in the constructor tells it whether to overwrite (false) or append (true).
|
|
|
|
|
Hello...
I have a question. Is C#.NET able to be used for application for data acquisition with sample rate 10ms ?
Are there probably any problems with GarbageCollector ?
If I read the data each 10ms, the garbage collector probably doesn't have time to run.
Must I use C or C++ for that ?
Thanks...
|
|
|
|
|
stancrm wrote: If I read the data each 10ms,
You're probably not "just" going to read it, obviously, and I guess you'd like to store it. Probably in memory, until you got enough to write to..
Isn't there some kind of device-driver for the gizmo that you want to read from?
BTW, Windows' does not guarantee a minimal amount of CPU-time and it might decide to put you on hold in favor of the other processes.
I are troll
|
|
|
|
|
When it comes to time critical stuff, Windows is pretty rubbish. Low(er) level C stuff talking directly to the hardware is pretty much the only way to go. Once that's done, it's possible to create a C# wrapper around the unmanaged stuff.
Disclaimer
This is just from my experience of messing with ASIO (audio stuff), and may not be accurate for your situation!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: When it comes to time critical stuff, Windows is pretty rubbish.
With the price of hardware one might decide on using a complete computer with QNX[^] as a peripheral device to the Windows host
I are troll
|
|
|
|
|
Cool... very cool
Link saved for further investigation!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi,
Windows is not a real-time system, it can't and doesn't guarantee a maximum latency time.
If you need to get something done every 10 msec no matter what, then you need something else.
OTOH if there is sufficient buffering, and all you need is accepting the data, but not immediately act on it, you might well be able to solve it with a Windows app. A simple example is data coming in over a serial line, say 1 character every 10 msec; if your buffer is 10KB it can hold 100 seconds' worth of data, so the app should be capable of processing that under all but the most extreme load conditions.
BTW: if the sample timing is important, you better have an external means as a sample clock; Windows sucks at creating small and precise time intervals.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I launch application B from application A. When i close application A i need to close application B.
I RDC to a remote server and launch application A and launch B from A. When i close A it looks for B and kills it. However it goes and kills application B in another RDC session.
How do i differentiate the process launched in the session i logged into?
Any help would be greatly appreciated.
|
|
|
|
|