|
I'm building a middleware program (client program) that receives data from a Sync Server (a hardware based device which pumps data to the network). The client program is suppose to:
1. Read all the data from the sync server.
2. Compare it to the formated data output (Hex value). If the data starts out as 0x08 then the client will be reading 9 bytes after that. If it shows 0x22 then the client will be reading 5 bytes instead.
The problem I have is the following:
1. How do I read from the Sync Server, when I know how the data format looks like but I have no control over the server side (since it simply pumps the data out to the network)?
2. Then if I'm reading the data in binary how do I convert that to Hex? Hex is easier to manipulate when I need to do a bitwise comparison.
The goal for now:
1. Get it to read the bits from the Sync Server
2. Print each bytes out individually and do some bitwise calculation on it to make sure that i can manipulate it.
Any help is very apprecieated
|
|
|
|
|
|
hello,
I would like to use xml file in multi-user enviroment.
Meaning, i need to allow adding lines to the xml.
my problem is that i don't know how to handle a situation when two users update the xml file at the same time. since the xml is re-written, the first changement will be lost.
so I need a way to prevent two or more access at the same time.
how to do so?
Eran.
|
|
|
|
|
You could use an object of FileStream class to access your XML-file, which provides some constructors that allow you to specify how the file will be shared by processes.
www.troschuetz.de
|
|
|
|
|
An XML file handle concurrency issues very poorly. Changes WILL be lost because you can only have one person writing to the file at any one time. Any writes MUST be done with an exclusive lock, since the entire XML file will be rewritten to the disk every time there is an update.
I would HIGHLY suggest moving the data to an actual SQL server, which is designed to handle concurrency... And I don't mean an Access database.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I've run in to a very strange problem. When I insert a breakpoint in my C# application, the debugger hangs for about 10 seconds and then my form is dead (but not closed). Even the thread it is executing in is gone. If I run the code without any breakpoints, all is fine.
There is one other who has experienced the same problem, but I cannot find out if he solved it or not. You can find his post on "http://www.talkaboutsoftware.com/group/microsoft.public.vsnet.debugging/messages/8688.html".
Has any one else come across this before?
Thanks!
|
|
|
|
|
I am new to .NET in general and Windows Forms programming in particular. As a part of a bigger project, I am trying to write a test application.
I have a ListView control whose number of rows and columns are determined by the user at runtime. To read the number of rows and columns, I have provided two textboxes. I have a refresh button, which when clicked, reads the number of rows and columns from the text boxes and tries to populate the ListView control.
When I run the program and click on the Refresh button, it appears as if nothing has happened in response to that click. The fact, however, is that the ListView control gets populated successfully, but no data is visible because the columns somehow overlap each other. I verified this by clicking inside the ListView control and pressing "CTRL +". On doing that, the columns auto-arrange themselves and become visible.
My gut feeling is that this is something really simple and stupid. Please help me out!
========================= CODE BEGINS ===========================================================
<code>using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ListViewTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox TB_Rows;
private System.Windows.Forms.TextBox TB_Columns;
private System.Windows.Forms.Label LABEL_Rows;
private System.Windows.Forms.Button BTN_Refresh;
private System.Windows.Forms.ListView LV_Data;
private System.Windows.Forms.Label LABEL_Columns;
private System.Windows.Forms.TextBox TB_BaseString;
private System.Windows.Forms.Label LABEL_BaseString;
private int m_iColumnCount;
private int m_iRowCount;
private string m_szBaseString;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.LV_Data = new System.Windows.Forms.ListView();
this.TB_Rows = new System.Windows.Forms.TextBox();
this.TB_Columns = new System.Windows.Forms.TextBox();
this.LABEL_Rows = new System.Windows.Forms.Label();
this.LABEL_Columns = new System.Windows.Forms.Label();
this.BTN_Refresh = new System.Windows.Forms.Button();
this.TB_BaseString = new System.Windows.Forms.TextBox();
this.LABEL_BaseString = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// LV_Data
//
this.LV_Data.Location = new System.Drawing.Point(16, 8);
this.LV_Data.Name = "LV_Data";
this.LV_Data.Size = new System.Drawing.Size(768, 248);
this.LV_Data.TabIndex = 0;
//
// TB_Rows
//
this.TB_Rows.Location = new System.Drawing.Point(52, 272);
this.TB_Rows.Name = "TB_Rows";
this.TB_Rows.Size = new System.Drawing.Size(96, 20);
this.TB_Rows.TabIndex = 1;
this.TB_Rows.Text = "5";
//
// TB_Columns
//
this.TB_Columns.Location = new System.Drawing.Point(227, 272);
this.TB_Columns.Name = "TB_Columns";
this.TB_Columns.Size = new System.Drawing.Size(96, 20);
this.TB_Columns.TabIndex = 2;
this.TB_Columns.Text = "8";
//
// LABEL_Rows
//
this.LABEL_Rows.Location = new System.Drawing.Point(13, 276);
this.LABEL_Rows.Name = "LABEL_Rows";
this.LABEL_Rows.Size = new System.Drawing.Size(40, 16);
this.LABEL_Rows.TabIndex = 3;
this.LABEL_Rows.Text = "Rows:";
//
// LABEL_Columns
//
this.LABEL_Columns.Location = new System.Drawing.Point(172, 274);
this.LABEL_Columns.Name = "LABEL_Columns";
this.LABEL_Columns.Size = new System.Drawing.Size(56, 16);
this.LABEL_Columns.TabIndex = 4;
this.LABEL_Columns.Text = "Columns:";
//
// BTN_Refresh
//
this.BTN_Refresh.Location = new System.Drawing.Point(680, 272);
this.BTN_Refresh.Name = "BTN_Refresh";
this.BTN_Refresh.Size = new System.Drawing.Size(104, 20);
this.BTN_Refresh.TabIndex = 5;
this.BTN_Refresh.Text = "Refresh";
this.BTN_Refresh.Click += new System.EventHandler(this.BTN_Refresh_Click);
//
// TB_BaseString
//
this.TB_BaseString.Location = new System.Drawing.Point(472, 272);
this.TB_BaseString.Name = "TB_BaseString";
this.TB_BaseString.Size = new System.Drawing.Size(168, 20);
this.TB_BaseString.TabIndex = 6;
this.TB_BaseString.Text = "Test";
//
// LABEL_BaseString
//
this.LABEL_BaseString.Location = new System.Drawing.Point(360, 275);
this.LABEL_BaseString.Name = "LABEL_BaseString";
this.LABEL_BaseString.Size = new System.Drawing.Size(104, 16);
this.LABEL_BaseString.TabIndex = 7;
this.LABEL_BaseString.Text = "Base String:";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(792, 405);
this.Controls.Add(this.LABEL_BaseString);
this.Controls.Add(this.TB_BaseString);
this.Controls.Add(this.BTN_Refresh);
this.Controls.Add(this.LABEL_Columns);
this.Controls.Add(this.LABEL_Rows);
this.Controls.Add(this.TB_Columns);
this.Controls.Add(this.TB_Rows);
this.Controls.Add(this.LV_Data);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Form1 form = new Form1 ();
Application.Run(form);
}
private void BTN_Refresh_Click(object sender, System.EventArgs e)
{
// Read the column count. This includes the "Item" column
this.m_iColumnCount = ReadColumnCount ();
// Read the row count. This includes the "Item" column
this.m_iRowCount = ReadRowCount ();
// Read the base string. Set it to "test" if it is empty
this.m_szBaseString = this.TB_BaseString.Text;
if (this.m_szBaseString.Length == 0)
this.m_szBaseString = "Test";
ClearListView ();
PopulateListView ();
}
/// <summary>
/// InitListView
/// </summary>
/// <param name="lv"></param>
/// <param name="bIsScrollable"></param>
private void InitListView (ListView lv, bool bIsScrollable)
{
lv.View = View.Details;
lv.GridLines = true;
}
/// <summary>
/// PopulateListView
/// </summary>
public void PopulateListView ()
{
InitListView (this.LV_Data, true);
// Create the columns
CreateColumns ();
// Create and populate the rows
ListViewItem[] listViewItemArray = null;
CreateListViewItems (out listViewItemArray);
//Add the items to the ListView.
this.LV_Data.Items.AddRange (listViewItemArray);
}
/// <summary>
/// CreateColumns
/// </summary>
private void CreateColumns ()
{
// Create the "Item" column first
//this.LV_Data.Columns.Add ("Item Column", -2, HorizontalAlignment.Left);
// Now create the data columns
for (int i=0; i < m_iColumnCount; i++)
this.LV_Data.Columns.Add ("Column " + i.ToString(), -2 * (i+1), HorizontalAlignment.Left);
}
/// <summary>
/// CreateListViewItems
/// </summary>
/// <param name="itemArray"></param>
private void CreateListViewItems (out ListViewItem[] itemArray)
{
itemArray = new ListViewItem[this.m_iRowCount];
for (int i=0; i < this.m_iRowCount; i++)
{
ListViewItem newItem = new ListViewItem (this.m_szBaseString + " " + i.ToString (), i);
AddSubItemsToListViewItem (i, newItem);
itemArray[i] = newItem;
}
}
/// <summary>
/// AddSubItemsToListViewItem
/// </summary>
/// <param name="iRowNumber"></param>
/// <param name="listViewItem"></param>
private void AddSubItemsToListViewItem (int iRowNumber, ListViewItem listViewItem)
{
for (int i=0; i < this.m_iColumnCount - 1; i++)
listViewItem.SubItems.Add (i.ToString());
}
/// <summary>
/// ClearListView ()
/// </summary>
private void ClearListView ()
{
this.LV_Data.Columns.Clear ();
this.LV_Data.Items.Clear ();
this.LV_Data.Clear ();
}
/// <summary>
/// ReadRowCount
/// </summary>
/// <returns></returns>
private int ReadRowCount ()
{
return ReadIntegerFromTextBox (this.TB_Rows, 15);
}
/// <summary>
/// ReadColumnCount
/// </summary>
/// <returns></returns>
private int ReadColumnCount ()
{
return ReadIntegerFromTextBox (this.TB_Columns, 10);
}
/// <summary>
/// ReadIntegerFromTextBox
/// </summary>
/// <param name="textBox"></param>
/// <param name="iDefaultValue"></param>
/// <returns></returns>
private int ReadIntegerFromTextBox (TextBox textBox, int iDefaultValue)
{
int iIntegerValue = iDefaultValue;
try
{
iIntegerValue = int.Parse (textBox.Text);
}
catch (FormatException)
{
iIntegerValue = iDefaultValue;
}
return iIntegerValue;
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}</code>
=========================== CODE ENDS ===========================================================
Thanks in advance,
-KMAnsari
|
|
|
|
|
private void CreateColumns ()
{
// Create the "Item" column first
//this.LV_Data.Columns.Add ("Item Column", -2, HorizontalAlignment.Left);
// Now create the data columns
for (int i=0; i < m_iColumnCount; i++)
this.LV_Data.Columns.Add ("Column " + i.ToString(), -2 * (i+1), HorizontalAlignment.Left);
}
ur setting the width of your columns to -2*(i+1) which will always be <0. I dont understand what ur trying to do here, but if u just change the width to a fixed one (70), everything works fine.
|
|
|
|
|
|
Hi all,
This is a simple question, but I haven't been able to find the answer in MSDN:
What does the ~ I have seen in some URLs mean? (such as "~/dwapp/default.aspx") I know what it means on a unix system - "your home directory" - but I haven't found the 1 line explanation I saw in *some* ASP book I've read.
Thanks in advance.
Frank Alviani
|
|
|
|
|
Simple - it means 'your home directory'. If you precede your URL with a ~, then it is absolute, and from the root of the application.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Some properties of ASP.NET controls (e.g. the ImageUrl property of e.g. the HyperLink control) expands this to the actual home directory.
In my own Page base class I use a similar function to acchieve the same. Here is an excerpt:
public class PageBase :
System.Web.UI.Page
{
public static string ReplaceTilde(
string path )
{
if ( path==null ||
path.Length==0 ||
path.IndexOf( '~' )!=0 )
{
return path;
}
else if ( HttpContext.Current==null ||
HttpContext.Current.Request==null )
{
string tilde = ConfigurationSettings.AppSettings["replaceTildeFallback"];
if ( tilde!=null && tilde.Length>0 )
{
tilde = tilde.TrimEnd( '\\', '/' );
return path.Replace( "~", tilde );
}
else
{
return path;
}
}
else
{
string tilde;
if ( HttpContext.Current.Request.ApplicationPath=="/" )
{
tilde = string.Empty;
}
else
{
tilde = HttpContext.Current.Request.ApplicationPath;
}
return path.Replace( "~", tilde );
}
}
} Maybe this is somehow useful to you.
--
Affordable Windows-based CMS: www.zeta-producer.com
|
|
|
|
|
Hi,
Why does the code below run the method correctly, but then create this error:
"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."
using System;<br />
using System.Collections.Generic;<br />
using System.Globalization;<br />
using System.Reflection;<br />
using System.Text;<br />
namespace ConsoleApplication1<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
Type t = typeof(Program);<br />
object[] argsg = new object[] { 100, 184 };<br />
MethodInfo teste= t.GetMethod("ComputeSum");<br />
teste.Invoke(null, BindingFlags.Default | BindingFlags.InvokeMethod | BindingFlags.Static, null, argsg, CultureInfo.InvariantCulture);<br />
}<br />
public static void ComputeSum(int num1, int num2)<br />
{<br />
Console.WriteLine(num1 + num2);<br />
Console.ReadKey();<br />
return;<br />
}<br />
}<br />
}<br />
Thanks
|
|
|
|
|
|
I ran the code and I did not received that exception. What are you trying to do exactly?
~javier lozano
(blog)
|
|
|
|
|
I'm trying to invoke the static method ComputeSum using reflection, this example is to show my problem, but it is part of a larger project. I'm using VC#S 2005 beta + .net 2
Thanks
|
|
|
|
|
I get a dialog error box during debug which reads:
"No source code available at the current location"
when the folowing code executes:
public DataSet Query(string Table,string QueryString)
{
try
{
DataSet dsDataSet = new DataSet();
SqlDataAdapter dbData = new SqlDataAdapter(QueryString,dbConn);
dbData.Fill(dsDataSet,Table);
return dsDataSet;
}
catch(Exception Err)
{
throw new Exception(Err.Message);
}
}
This same code has been running fine for months, now when I went back to re-work a certain application, it now errors out on the Fill method. But not all the time.
This is driving me crazy since the error is sporatic.
any help out there?
I'm positive that both parameters are valid, I've checked them many many times.
|
|
|
|
|
One would imagine that there is no source code available because it's blowing up within the DB call, and that it probably blows up depending on the query string
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Well if there is something wrong with the query strin you'd think it would throw an exception rather than blowing up. But that aside, its not the string, because it doesn't blow up every time and the Query string is the same everytime.
|
|
|
|
|
This just means something else is handling the exception rather than your code. When the debugger is attached and exception is thrown that is not caught the debugger steps in and tries to show you where but fails because there is no pdb or the source never existed.
Without more information who knows what is wrong.
|
|
|
|
|
Well get this. I reinstalled VS.NET and the problem is gone.
Don't know why or how....something must have gotten corrupted.
What a waste of time.
|
|
|
|
|
Is there a way to debug an ActiveX control written in VB6 using an exe written in C#???
I know that COM Interop creates some intermediate things that .NET can understand and deal with.
My .NET app uses the control from VB6 and raises an error on exit - so I only can guess that the problem is inside my VB6 control. But how can I debug it???
Vad.
|
|
|
|
|
I could be wrong here, but you could run the control under the debuggers in VS.NET 2002/2003. But, you can't make any changes to the code without recompiling the control with Visual Basic 6. The VB.NET compilers won't work for you in this case because they don't target ActiveX control natively.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Yes, I can run my control under VB.NET but first I would have to convert it into compatible VB.NET code. Such convertion would force me to make many changes to the code because my control is rather complicated and it could happen that the reason of error would eliminate by itself...
Nevertheless, thanx for advise. I will mind if I find nothing more!!! ))
|
|
|
|
|
Hi,
Not sure if this has been commented already, I searched for it, but nothing showed up.
I am having a weird problem: I've been developing an application for 3 months already, but since a couple of days ago, every time I put a new icon in a form, it shows in design mode, but it doesnt show up at run time. This happens even with old W3.1 icons, and on different forms. Icons I was working with normally, refuse to show if I add them again in a different form.
This is driving me mad since I dont have a clue about what could be causing this. Maybe my Visual studio 2003 has gone nuts? Out of memory?
Any help would be GREATLY appreciated
Thanks in advance
|
|
|
|