|
Hi guys
I am working on a project in which i need to add a pic an save it in any instance e,g dll etc. How can i create dll in running of an application and add something to it.
any link or hint will be appreciate.
|
|
|
|
|
|
I have a dataset with multiple tables in it. This dataset is created by reading an XML which has nested tables which is shown below.
<allocate>
<cabin cabintypeId="3" cabinType="deluxe" shareFlag="true" OccupancyType="TripleShare"
sameGender="true" cabinId="001" Adult="2" Child="0" Infant="0" availablebeds="1">
<occupant firstname="Micheal" lastname="Lauzon" age="adult" gender="male" nationality="UnitedStates"
usePackage="yes" roomrate="100" presold="true" />
<occupant firstname="John" lastname="Martin" age="adult" gender="male" nationality="Australia"
usePackage="yes" roomrate="100" presold="false" />
</cabin>
<cabin cabintypeId="1" cabinType="Standard" shareFlag="true" OccupancyType="single" sameGender="true"
cabinId="005" Adult="1" Child="0" Infant="0" availablebeds="0">
<occupant firstname="Jacob" lastname="Dror" age="adult" gender="male" nationality="UnitedStates"
usePackage="yes" roomrate="90" presold="false" />
</cabin>
</allocate>
once it is transferred to a dataset, it is divided into two independent tables "Cabin" and "occupant". With what reference can I read the data and identify it. What I mean is, in the above XML Set, how can I differentiate that for cabintypeId="3" there are two occupants named John and Michael. As well as for cabintypeId="1" occupant firstname="Jacob". As Cabin and Occupants are two different tables. I suppose I need to identify some Key value for the Relation defined internally for the datatables. How can I do this? Please help me out.. If I am not clear, I can Explain it more...
Thanks... Rijz
|
|
|
|
|
Hi,
In socket programming, I listen to the port using,
this.serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
this.serverSocket.Bind(localEndPoint);
this.serverSocket.Listen(0);
this.serverSocket.BeginAccept(AsyncCallBackOnAcceptMethod, null);
When a client tries to connect to the port, I am able to connect to the client and send and receive messages.
The problem is, when the client disconnects by accident (ie... Killing the client application), I have to close the socket. How the server can be notified of the client disconnection? Is there any event for this in the socket class? or Do I need to ping the client frequently at regular intervals to check for connectivity?
Raja Pandian
|
|
|
|
|
Hi
There's no event for disconnecting in Socket or any other network class in .net (as far as i know...)
but there's an easy way to detect connection loss...
if i use sockets, i always use to write synchron and read asynchron.
that means, after connection you do a BeginRead on the socket (or network stream...).
in your callback - method you call EndRead with the IAsyncResult you receive. if EndRead returns 0 the connection is lost.
this gives you an immediate "Event" when the client disconnects correctly. if the Disconnect is accidently (like someone plugs out the network on the client, or the client crashes) you will get the event after the timeout (about 10-20 seconds i think...)
hope this helps
greets
m@u
|
|
|
|
|
I am working on creating a rich text box control to serve as a "visible" log of events. In order for it to work properly, it must be able to accept log entries from different threads.
I tried following the recommendations given by Microsoft on this page: http://msdn2.microsoft.com/en-ca/library/ms171728.aspx
The recommended method in the examples is to call a BackgroundWorker and perform the update in the BackgroudWorker's RunWorkerCompleted event.
In order to ensure that the text was available to the RunWorkerCompleted event, I added a DoWork event that, essentially, takes the text from it's EventArgs.Argument and puts it in the .Result area.
I have included a stripped down version of the code below. Executing this with only one call to AddEntry works wonderfully: AddEntry calls AddEntryInBackground.RunWorkerAsync, DoWork is executed, then RunWorkerCompleted and the desired text shows up in the textbox.
However, when there is a second call to AddEntry, it all falls apart. It seems as though the first call's DoWork execution is interrupted by the second call and never completes. The second call waits forever for IsBusy to be false.
I am unable to find anything that may explain why this occurring - Microsoft recommends this procedure as the "thread-safe" way to avoid simultaneous access to a form's control - which it does (in the same way that deliberately driving your car off a cliff keeps you from accidentally driving your car off a cliff). It appears that the BackgroundWorker only "works" for a very limited amount of time, after which control is passed back to the main thread and the BackgroundWorker remains in a permanent unfinished state.
Can anyone point me in the right direction?
Many thanks,
The main form
using System;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
namespace TestVisibleLog
{
public class VisibleLog : RichTextBox
{
private string timeStampFmt;
private int maximumBytes;
private string[] timeStampTokens;
private BackgroundWorker AddEntryInBackground;
public VisibleLog ( )
{
this.Enabled = false;
timeStampFmt = "";
maximumBytes = 512;
timeStampTokens = "dow,yoc,moy,dom,hh,mm,ss".Split(',');
this.Text = "";
AddEntryInBackground = new System.ComponentModel.BackgroundWorker();
AddEntryInBackground.DoWork += new System.ComponentModel.DoWorkEventHandler(AddEntryInBackground_DoWork);
AddEntryInBackground.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(AddEntryInBackground_RunWorkerCompleted);
}
public string TimeStampFormat
{
set
{
timeStampFmt = value;
if ( value != "" )
{
timeStampFmt += ": ";
for ( int index = 0; index < timeStampTokens.Length; index++ )
timeStampFmt = timeStampFmt.Replace(timeStampTokens[index], "{" + index.ToString() + "}");
}
}
}
public int MaxBytes
{
set
{
maximumBytes = value;
}
}
public void AddEntry ( string EntryText )
{
while ( AddEntryInBackground.IsBusy )
Thread.Sleep(100);
AddEntryInBackground.RunWorkerAsync(EntryText);
}
private void AddEntryInBackground_DoWork ( object sender, DoWorkEventArgs e )
{
string entryFormat = timeStampFmt + "{" + (timeStampTokens.Length).ToString() + "}.";
string logEntry = string.Format(entryFormat,
DateTime.Now.DayOfWeek.ToString().Substring(0, 3),
(DateTime.Now.Year % 100).ToString("D2"),
DateTime.Now.Month.ToString("D2"),
DateTime.Now.Day.ToString("D2"),
DateTime.Now.Hour.ToString("D2"),
DateTime.Now.Minute.ToString("D2"),
DateTime.Now.Second.ToString("D2"),
e.Argument);
e.Result = logEntry;
}
private void AddEntryInBackground_RunWorkerCompleted ( object sender, RunWorkerCompletedEventArgs e )
{
int overage = this.Text.Length + ((string)(e.Result)).Length + 1 - maximumBytes;
if ( overage > 0 )
{
int cutoff = this.Text.IndexOf("\n", overage);
if ( cutoff == -1 )
this.Text = (string)e.Result;
else
this.Text = this.Text.Substring(cutoff + 1) + "\n" + (string)e.Result;
}
else
this.Text += ((this.Text.Length > 0) ? "\n" : "") + (string)e.Result;
}
}
}
The new control
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace TestVisibleLog
{
public class Form1 : Form
{
public Form1 ( )
{
InitializeComponent();
this.statusLogBox.TimeStampFormat = "yoc/moy/dom-hh:mm:ss - ";
this.statusLogBox.AddEntry("This is entry 1");
System.Threading.Thread.Sleep(60000);
this.statusLogBox.AddEntry("And here is another entry");
}
private System.ComponentModel.IContainer components = null;
private VisibleLog statusLogBox;
protected override void Dispose ( bool disposing )
{
if ( disposing && (components != null) )
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent ( )
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
statusLogBox = new VisibleLog();
this.SuspendLayout();
this.statusLogBox.Location = new System.Drawing.Point(13, 13);
this.statusLogBox.Name = "statusLogBox";
this.statusLogBox.ReadOnly = true;
this.statusLogBox.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Both;
this.statusLogBox.Size = new System.Drawing.Size(256, 241);
this.statusLogBox.TabIndex = 0;
this.statusLogBox.Text = "";
this.statusLogBox.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
this.statusLogBox.Enabled = true;
this.Controls.Add(statusLogBox);
this.ResumeLayout();
}
}
static class Program
{
[STAThread]
static void Main ( )
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Clive Pottinger
Victoria, BC
|
|
|
|
|
That is not the way BackgroundWorkers are meant to be used. They are typically created to do some background work, report progress (if any) on the UI thread, and then indicate completion of the background work on the UI thread.
If all you need to do is update text from a non-UI thread, you are much better off using Control.Invoke[^] or Control.BeginInvoke[^].
Your code would then look like
delegate void StringInvoker(string t);
void AddEntry(string text)
{
if (this.InvokeRequired)
{
this.Invoke(new StringInvoker(AddEntry), text);
return;
}
this.Text = ...;
}
}
|
|
|
|
|
Thank you Senthil.
When I read the page on the MSDN site, the Invoke seemed to make the most sense. However, I ran into a problem which I thought might have been caused by using Invoke. Since Microsoft says
"The preferred way to implement multithreading in your application is to use the BackgroundWorker component" I thought I would set the code up that way.
Now I believe my initial problem was not related to my use of Invoke. I will put the code back and track down my problem.
Thanks again. I will figure out C#, and by the year 2034 I'll be qualified to write thread-safe, XAML-based, SQL powered Hello World programs on any XP systems that may still be around
Clive Pottinger
Victoria, BC
|
|
|
|
|
Thanks again, Senthil.
I was wondering... do you have any idea why my use of BackgroundWorker failed? I thought I set it up correctly. Now that I have been exposed to it, I think I see were it could be useful in the future and I'd like to know that I can use it without getting locked up.
Clive Pottinger
Victoria, BC
|
|
|
|
|
BackgroundWorker is meant to be used for running long running operations in the background - essentially operations for which you would create a Thread yourself. The difference is that you can use the BackgroundWorker to report progress and completion without having to manually use Invoke or BeginInvoke. Bulk file copy and application initialization (with a splash screen indicating progress) are two places where a BackgroundWorker would work well.
The reason I suggested that you use Invoke/BeginInvoke was that you were not running any big operations in DoWork, you were simply using it to marshal the call to the UI thread by setting the Result property. That is exactly what Invoke/BeginInvoke is supposed to do. What's more, the BackgroundWorker's DoWork will run on a threadpool thread - this is in addition to the other thread on which you're doing the actual work. Invoke/BeginInvoke will not use a threadpool thread, it simply causes the delegate to execute on the UI thread.
|
|
|
|
|
Hi All,
Is it possible to flush the code output by JIT?. I want to force the CLR to recompile on the fly.
This problem I am investigating is similar to self modifying code.
Jeff
|
|
|
|
|
|
I googled. Got nothing. I have a class called Square which extends PictureBox. Now I have a class called Tank which extends Square:
public class Square : PictureBox
{
public Square (int type, int row, int col){}
}
public class Tank : Square
{
public Tank (Bitmap[] images, int type, int row, int col){}
}
I tried super like Java uses but it doesn't exist so how do I call Square's constructor from Tank's constructor?
|
|
|
|
|
public Tank (Bitmap[] images, int type, int row, int col) : base(type, row, col) {
}
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
|
hi
how can i convert access database to sdf database for PPC ?
thanks
|
|
|
|
|
I'm trying to update a project to use System.XML.Linq and I'm now happily working with XDocument and XElement etc... It's very cool by the way if you haven't tried it.
The only problem I have is in one method I have to pass the full xml as a string, but XDocument.ToString() only returns the root and child nodes and not the xml header. Previously I used XMLDocument.OuterXML.
I there any equivalent in XDocument or a way of converting an XDocument to an XMLDocument?
*Edit*
I've found a 'dirty' way of doing it:
string xmlString = myXDocument.Declaration.ToString() + myXDocument.ToString(SaveOptions.DisableFormatting);
but there must be a better way than this!
modified on Sunday, January 20, 2008 11:54:14 AM
|
|
|
|
|
What's wrong with the "dirty" way?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Nothing I suppose, I expected a new class specifically designed to work with xml to have a method that would either return the xml as a string, or an XmlDocument at least, for compatability.
I just thought I was missing something obvious.
It appears that the only way to actually get full valid xml out of of it after you've finished manipulating data is to either save it to disk or to use a TextReader.
I've created my own class inherited from System.Xml.Linq.XDocument and added ToXmlDocument() and two ToXmlString() methods (one that allows formatting) so I have the functionality I need.
|
|
|
|
|
hye,
(Using DShowNET)When i call this FindPin(), it returns nagative value.I m calling it like this;
ICaptureGraphBuilder2 capGraph;
IPin pin;
Guid pc = PinCategory.Capture;
Guid pt = Guid.Empty;
int hr = capGraph.FindPin(
Device(which i found attachd),
1,
ref pc,
ref pt,
false,
0,
p);
and it returns negative value(-214...). I checkd the parameters during debugging, no problem in them then Whats wrong m i doing?
B!z
|
|
|
|
|
B!Z,
I don't know anything about ICaptureGraphBuilder2, but from your code you don't construct the capGraph or pin object.
This might be the problem...
Regards,
Gareth.
|
|
|
|
|
No. coz last time when another function returned this same negative value (-214...), the problem was not in that function itself. And BTW i wrote "ICaptureGraphBuilder2 capGraph;", its not actually like that(coz the code was bit lengthy so included that method only). i just wanted to tell that capGraph is actully its object.Anyways thx for the reply.
Anyone else who worked using DShowNET by .NET master?
B!z
|
|
|
|
|
Hi all,
I have a question regarding a Listview focus: Whenever this control loses focus to another control (e.g. checkbox that's being clicked at the same form), the selected lines are switched from blue to grey. Is there a way to keep the listview always focused, without calling its Focus() method every time another control gets it?
Thanks a lot,
Eyal.
|
|
|
|
|
I assume you mean that you want it always to appear the same as it does when it has the focus.
If so, you'll nead to create your own class inheritting from ListView and override the OnPaint event and possibly the OnLostFocusEvent.
|
|
|
|
|
Hi all,
I need to reconstruct the exact view of a listview after updating it's data. There is no problem if all the lines are visible. However, if some of it is hidden (a situation where a vertical scrollbar appears), updating the list always brings the first line to be first viewed, meaning that some lines that were previously visible are now hidden.
Does anyone knows how to reconstruct the exact location as before the update procedure?
Thanks,
Eyal.
|
|
|
|
|