|
|
Could you give me a C# sample code for using P/Invoke with the method CmdLoadFromResource()?
|
|
|
|
|
How could I open an Acrobat document from C# program? I do not want to read and get data in program. Only want to open it from a link.
|
|
|
|
|
Use the Process class:
System.Diagnostics.Process.Start("C:\Document.pdf");
Hope that helps!
|
|
|
|
|
Hi,
I started a new thread in my project which will call a function inside a class. But the thread doesn't calling the function. What can I do?
The function, which work in a new thread is just the function used in RssReader Demo, a article in this forum. I want to do further processing the items retrieved by RssReader, so I put the function which will use the RssReader class in my class. Is it a problem?
Tahsin Sayeeda Moon
(B.Sc. in Computer Science & Engineering
Internation Islamic University Chittagong)
|
|
|
|
|
Tahsin Sayeeda wrote: What can I do?
Hard to say without seeing pertinent portions of your source code.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hello Sayeeda,
When running a new thread, you have to first instantiate it, and then call the Start() method on the thread object you've instantiated.
You should do something like this:
Thread t = new Thread(/*Your parameters goes here*/);
t.Start();
Your thread will not start running the function until you call the Start() method.
Anyway... I think if you post some of your code here we could help you further than that.
Shy.
-- modified at 4:59 Sunday 7th May, 2006
|
|
|
|
|
Hi,
Actually after reading the rules of posting a question, I got afraid to send my code!
Here how I called the thread.
CNews cnews = new CNews();
Thread thread = new Thread(new ThreadStart(cnews.readRss));
thread.Start();
And here is the function inside CNews class
public void readRss()
{
RssReader rssReader = new RssReader();
rssReader.FeedLoaded += new EventHandler(rssReader_FeedLoaded);
rssReader.ItemAdded += new EventHandler(rssReader_ItemAdded);
rssReader.Error += new RssReaderErrorEventHandler(rssReader_Error);
RssFeed feed = rssReader.Retrieve("C:\\news.xml");
if ( feed.ErrorMessage == null || feed.ErrorMessage == "" )
{
int i;
for(i=0;i<itemsFound;i++)
{
ItemDescription[i] = feed.Items[i].Description;
}
}
}
I use the code from Rss Reader demo by smallguy78 as I previously mentioned. Please tell me if there is anything more I’ve to send from my code.
Actually the code runs okay in my main form. But I fail to get the value from it in my CNews class (using get and set properties). I have to do further processing with those values which I did in my class. So I put the function in my class. Then the thread doesn’t calling the function!
I can also send my full project if anyone interested I mean need to see it.
Tahsin Sayeeda Moon
(B.Sc. in Computer Science & Engineering
Internation Islamic University Chittagong)
-- modified at 14:43 Sunday 7th May, 2006
|
|
|
|
|
I've no idea what's this Rss Reader demo by smallguy78...
Would you post a link?
Shy.
-- modified at 6:54 Sunday 7th May, 2006
|
|
|
|
|
|
How did you conclude the thread is not getting called? Did you try, for instance, setting a breakpoint in readRss and checking if it got hit? And are you sure the code starting the thread is actually executing?
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Hi,
Actually I tried to call another function by the new thread. The function is in main form which will only show something in a text field. The nothing is showing in that field.
And I also set a breakpoint to see what’s going on, the thread starts but it doesn’t call the function. I can’t get into my demo function.
Tahsin Sayeeda Moon
(B.Sc. in Computer Science & Engineering
Internation Islamic University Chittagong)
|
|
|
|
|
Tahsin Sayeeda wrote: Actually after reading the rules of posting a question, I got afraid to send my code!
By just reading them, you are way ahead of most posters.
---
b { font-weight: normal; }
|
|
|
|
|
I always call Thread.Sleep(0) in the parent after starting a thread. There's an issue with uniprocessors not starting child threads if the main thread does not give up its time slice.
|
|
|
|
|
I am porting a VB 6.0 application to C# that automates navigation of multiple web pages within a site and extracts information from some of the pages. One of the pages contains a listbox containing a number of countries. The default value that is set is not the value I need to use.
The HTML in the web page looks like this:
<select name="country" style="" onchange="" multiple id="countryList" size="7">
<option value="*" selected> All Countries and Territories </option>
<option value="------0">------</option>
<option value="AU"> Australia </option>
<option value="AT"> Austria </option>
<option value="BE"> Belgium </option>
<option value="BR"> Brazil </option>
<option value="CA"> Canada </option>
<option value="CN"> China </option>
<option value="DK"> Denmark </option>
<option value="FI"> Finland </option>
<option value="FR"> France </option>
<option value="DE"> Germany </option>
<option value="HK"> Hong Kong </option>
<option value="IT"> Italy </option>
<option value="JP"> Japan </option>
<option value="NL"> Netherlands </option>
<option value="NO"> Norway </option>
<option value="PT"> Portugal </option>
<option value="SG"> Singapore </option>
<option value="KR"> South Korea </option>
<option value="ES"> Spain </option>
<option value="SE"> Sweden </option>
<option value="CH"> Switzerland </option>
<option value="TW"> Taiwan </option>
<option value="GB"> United Kingdom </option>
<option value="US"> United States </option>
</select>
In VB6 the selected value is changed this way:
' De-select the first (default) value in the list
wb1.All("country").Options(0).Selected = False
' Select the 26th item (zero-based index) in the list
wb1.All("country").selectedIndex = 25
wb1 is an HTMLDocument object.
I cannot figure out how to access the Options collection or the selectedIndex property with the .NET 2.0 Webbrowser object. Any ideas how I can do this in C#?
|
|
|
|
|
I don't have access to my development system at the moment to try this out. So, I would appreciate some input as to whether or not this might work:
IHTMLDocument3 iDoc3 = (IHTMLDocument3)wb1.Document.DomDocument;
IHTMLSelectElement eltCountryList = iDoc3.getElementById("countryList");
eltCountryList.selectedIndex = 25;
For now, just ignore the absence of error checking for null pointer values. Is this about the right approach? Will I be able to modify the <SELECT> element's 'selectedIndex' property without any kind of initialization or setup code (sometimes it looks like the HTMLDocument contained in the webbrowser control is read-only)? Do I need to iterate through each <OPTION> element in the list using the IHTMLOptionElement interface and set the 'selected' property to false?
|
|
|
|
|
Here's the code that properly selects an element from the listbox:
HtmlElement eltCountryList = webBrowser1.Document.GetElementById("countryList");
HtmlElementCollection eltOptions = eltCountryList.GetElementsByTagName("option");
foreach (HtmlElement op in eltOptions)
{
op.SetAttribute("selected", ""); // de-select all items in the list
}
eltOptions[25].SetAttribute("selected", "True"); // set "United States" as the selected item
|
|
|
|
|
I am taking a 2nd quarter C# programming class at the local community college. Since I took the 1st quarter a couple of years ago and it was in VB, I am getting hammered by not knowing how to do things in the IDE for C#.
I can figure out the logic of what I am trying to do, but get baffled and stymied in my attempts to create projects do to not knowing how and what to do in the IDE.
These are really simple things like create a class or turn on validation.
I have multiple C# books, but what I am missing is so trivial the books don't even really cover it.
Where is a good tutorial or cheat-sheet to cover how to do basic things in IDE while programming for C#?
TIA,
Kevin
|
|
|
|
|
When in doubt right click.
For example: To add a new class you are adding it to the "Project" so right click on the "Project" Node in the "Solution Explorer" tree. Then look at the items in the context menu. They should provide you with a clue.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
The .NET documentation that comes along with Visual Studio includes tons of material about using the IDE. Paste this into your browser's Address box to get started:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_cscon/html/e10e2cba-641f-47a3-88a3-6748965254d7.htm
Josh
|
|
|
|
|
hi
how to use progressbar when my operation is working ?
thanks..
|
|
|
|
|
well if [your operation] uses a loop then before the loop assign the progressbar's maximum value to the number of iterations being executed. Set the progressbar's value to some value i.e. 1. Then inside the loop call progressbar.PerformStep(). However, bear in mind that if your operation is intensive and gives you the freeze gui look then you will need to use delegate(i.e. asynchronous callbacks) or background worker thread to update the progressbar.
hope this helps.
-- modified at 20:29 Saturday 6th May, 2006
edited items in [].
|
|
|
|
|
Hello all,
I'm trying to build my own very-simple Socket wrapper class. The first class (which I'm trying to do now) is for listening. The most important thing I am trying to implement is OnConnect, Ondisconnect, and OnReceive.
I've done OnConnect and it's working perfectly. But now I've spent alot of time trying to implement the OnReceive method, but I get a strange result!
..
..
..
<br />
public void listen(int port)<br />
{<br />
listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);<br />
listener.Bind(new IPEndPoint(IPAddress.Any, port));<br />
listener.Listen(10);<br />
listener.BeginAccept(new AsyncCallback(myOnConnect), listener);<br />
}<br />
<br />
public void myOnConnect(IAsyncResult ar)<br />
{<br />
Socket sock = (Socket)ar.AsyncState;<br />
OnConnect(myId);<br />
try<br />
{<br />
if (sock.Connected)
{<br />
AsyncCallback recieveData = new AsyncCallback(myOnReceive);<br />
sock.BeginReceive(m_byBuff, 0, m_byBuff.Length, SocketFlags.None, recieveData, sock);<br />
}<br />
}<br />
catch(Exception e)<br />
{<br />
MessageBox.Show("Err: "+e.ToString());<br />
}<br />
listener.BeginAccept(new AsyncCallback(myOnConnect), listener);<br />
}<br />
<br />
public void myOnReceive(IAsyncResult ar)<br />
{<br />
Socket sock = (Socket)ar.AsyncState;<br />
try<br />
{<br />
int nBytesRec = sock.EndReceive(ar);<br />
if( nBytesRec > 0 )<br />
{<br />
string msg = Encoding.ASCII.GetString(m_byBuff, 0,nBytesRec);<br />
OnReceive(myId, msg);<br />
AsyncCallback recieveData = new AsyncCallback(myOnReceive);<br />
sock.BeginReceive( m_byBuff, 0, m_byBuff.Length, SocketFlags.None, recieveData, sock);<br />
}<br />
else<br />
{<br />
OnDisconnect(myId);<br />
}<br />
}<br />
catch<br />
{}<br />
}<br />
|
|
|
|
|
tmp0 wrote: if (sock.Connected) //the strange this is, this always returns false
I have never used Async Sockets in .NET.
sock is your Listening socket and therefore will not be connected. You need to call listener.EndAccept(ar) to get the socket object that is the "connected" socket.
try<br />
{<br />
Socket sessionSock = sock.EndAccept(ar);<br />
if (sessionSock.Connected)<br />
<br />
Hope that helps.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Hello tmp0...
When using Socket's async functions it's important to call the EndX methods inside your callback functions...
In BeginAccept()'s case, you have to call EndAccept(), which will return a new CONNECTED socket.
Only then could you take the listener object you've created, and call BeginAccept() again.
With that said, your myOnConnect() callback should look something like that:
public void myOnConnect(IAsyncResult ar)
{
OnConnect(myId);
try
{
Socket sock = listener.EndAccept(ar);
listener.Close();
if (sock.Connected)
{
AsyncCallback recieveData = new AsyncCallback(myOnReceive);
sock.BeginReceive(m_byBuff, 0, m_byBuff.Length, SocketFlags.None, recieveData, sock);
}
}
catch(Exception e)
{
MessageBox.Show("Err: "+e.ToString());
}
listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
listener.BeginAccept(new AsyncCallback(myOnConnect), listener);
}
Hope this helps...
Tell me the results
Shy
-- modified at 4:52 Sunday 7th May, 2006
|
|
|
|