|
The answers you got are valid. There is no way to do this without iterating through the List because there is no conversion between a List and a DataTable. Even if there was, interanlly, it would be iterating over the List anyway.
|
|
|
|
|
|
|
Or Bing? Sorry it's a joke spilling over from the Lounge.
Craigslist Troll: litaly@comcast.net
"I have a theory that the truth is never told during the nine-to-five hours. "
— Hunter S. Thompson
|
|
|
|
|
You have 2 answers to your QA question, can you please accept them? It is pretty rude not to reward people that took the time to help you.
Craigslist Troll: litaly@comcast.net
"I have a theory that the truth is never told during the nine-to-five hours. "
— Hunter S. Thompson
|
|
|
|
|
Hello
I have problem with following:
Have WinForm app, in which i have PDF Viewer axAcroPdf, and in startup, i load pdf file with form fields in it.
Next, I have button, which when it pressed, need to read changes made by user in loaded pdf file in viewer, and use this data..
User have "save" button on controls bar of viewer, which ask user when and how save copy of file. I don't need that, and i disabled that controls bar.
Is there any way to perform that save button of viewer with predefined path and filename?
I had idea to programatically save that updated file like temp file, and open it with iTextSharp PDFReader, and use that data from populated fields in pdf file, and delete than delete temp file, but i have no idea how to perform that save button from control bar of viewer..
i'm using c# 2010
thanks
|
|
|
|
|
64 bit Console linked to 32 bit dll? I know and in fact tried it won't work. You can add reference but you'd have runtime exception "Could not load fle or assembly ... one of its dependencies. An attempt was made to load a program with incorrect format"
But have I missed anything? Any magic whereby 64 bit host can reference and load a 32 bit dll into its process?
dev
|
|
|
|
|
Windows does not support heterogeneous processes, each process has to be either entirely 32-bit or entirely 64-bit, there is no way around that.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I created some client server code that talks back and forth to each other using TCPListener -> TcpClient -> NetworkStream. Everything it working great. The data being sent from the client is showing up on the server with data intact. However, there is one problem; the data is out of order.
A simple example is:
Client sends:
1 2 3 4 5 6 7 8 9 10
and the Server receives:
1 2 3 5 6 7 8 4 9 10
I'm happy that the 4 makes it there but I'd just like it to come after the 3.
Is this a short coming of the TCP stack? Am I asking too much? I know tcp is supposed to ensure that data gets there but does it ensure that it gets there in order?
Some psuedo code as to the main line items:
m_Listener = new TcpListener(m_ServerPort); <-- Port 8000 if it matters
m_Listener.Start();
TcpClient m_Client = m_Listner.AcceptTcpClient();
NetworkStream m_NetworkStream = m_Client.GetStream();
The below code is run in a thread devoted to reading in data from that network stream. This thread code is via a BackgroundWorker.
while (m_Client.Connected)
{
byte[] buffer = new byte[4];
int readBytes = m_NetworkStream.Read(buffer, 0, 4);
if (readBytes == 0)
break;
ChatCommandType cmdType = (ChatCommandType)(BitConverter.ToInt32(buffer, 0));
string cmdTarget = "";
buffer = new byte[4];
readBytes = m_NetworkStream.Read(buffer, 0, 4);
if (readBytes == 0)
break;
int ipSize = BitConverter.ToInt32(buffer, 0);
buffer = new byte[ipSize];
readBytes = m_NetworkStream.Read(buffer, 0, ipSize);
if (readBytes == 0)
break;
cmdTarget = System.Text.Encoding.ASCII.GetString(buffer);
}
There is more to the read in code but this is the gist.
It runs rock solid except when the entire messages get flipped.
I'd appreciate any random thoughts on this. I've been banging my head on it for 2 days now and need a fresh pair of eyes.
I could implement my own sync code where it won't send 5 until it gets a response on 4 but I thought TcpClient would be the one to handle that and not higher up the stack.
Thanks,
|
|
|
|
|
There probably is way too much information missing here, you haven't shown the sending stuff at all, and it isn't clear to me where exactly the two receiving code snippets are located (and they only deal with the internals of a message, not what happens to the messages as a whole). How many threads are involved? etc.
If you want to get this solved, I suggest you add logging, i.e. sending short lines of information (with HH:mm:ss.fff timestamps, and the current thread ID (I suggest the lowest byte in hex), and essential data values) to a file, for both the sender and the receiver.
BTW: I noticed there isn't any safety built in; when a stream gets out of sync, the wrong bytes may end up forming a length value, or negative bytes may end up being ASCII decoded. You should never assume all will go right all the time!
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
TCP does preserve order, so if you are seeing this, then either you are sending the data out of order, or your receiving code is messing with the order. If you are sending or receiving in multiple threads for the same socket then that could happen, for example if to create the 'numbers' you are spinning off execution of each one to a thread pool or something.
You haven't posted any sending code which I suspect is where the problem lies, as it is unusual to have more than one thread reading the same socket, though if you were doing that it could also mess things up.
By the way your receive code is quite unsafe. Think about what happens if you receive 3 bytes, or 11. Check ClientInfo.ReadInternal from my sockets library to see how to cope with this.
|
|
|
|
|
Octantis wrote: I'd appreciate any random thoughts on this
Besides what is said by the others....
You have some 'method' that you are using to determine what "order" the packets represent.
That 'method' is flawed. Thus you think the order that is being sent is "1 2 3 4 5..." but in fact it is "1 2 3 5 ...4"
|
|
|
|
|
I think you and the others might be right with them being sent in the wrong order.
I believe this is what is happening. I spawn a fire and forget thread to send out the data. I think the system is servicing the threads in a different order than what they were created. I use a semaphore on the socket to ensure the writing is done without interruption from other threads ensuring the whole message is sent out. I'm thinking I just need to use a single sending thread and build a queue for outgoing data.
I'm working on tracking the threads to verify my claim. I'll post more when it shows up.
BTW thanks for the help. You guys simply saying check your sending code was enough to make me take a second look. I appreciate you taking the time to read this.
Tim
|
|
|
|
|
there is no ordering of threads, when they are "ready", i.e. have some work to perform and not waiting on something, then the operating system can pick any N of them (for N cores), assuming all have the same priority. If you want to order them, you need synchronization, which probably annihilates the advantages of having multiple threads anyway.
it does not make sense to me to use multiple threads for sending messages that have to have a specific order; you might have more than one thread coming up with messages (and storing them somehow), but when order is important, you'd better have only one sender thread. And probably manufacturing the messages isn't worth the trouble of multiple threads either, so I suggest you keep it simple.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Octantis wrote: I'm working on tracking the threads to verify my claim.
No need to verify anything.
Threads do not run in "order" unless you add something explicitly that forces them into some order (causes them to block or otherwise limits how they run.)
|
|
|
|
|
The answer as expected did point to the sender and his using of a throw away thread to send a single message. Now instead I drop those messages into a queue and then send them off within its own separate thread. Problem solved.
You guys did bring up the question of unsafe read practices. Specifically when things would get out of sync. I understand what you mean by an errant byte being assumed as a string or a size. In general how do you guys handle that? Put in super unique character strings like #$$# with the next following character being the size and then seeking the buffer looking for those values? The TCP layer should ensure that the data shows up (eventually) unmolested. So something like that would only serve to hide errors in the sending code and not something outside your realm of control.
I'll mark this problem as solved. Once again thanks for the help.
|
|
|
|
|
Presumably you mean sending via TCP.
I don't send data - I send messages.
Data is what I want delivered. A message is the envelope which contains the data. At a minimum it contains a value that indicates the size of the data. So the message contains the size and then the data.
Sometimes I put other things in there like data type identifiers.
|
|
|
|
|
Hello,
I have a pdf file with the arabic name. and i want to view in adobe pdf reader.
if the file name in english then PDF file view successfully.
but when i load the arabic filename then its dosent view.
So please suggest me, how to view arabic file name PDF.
Thanks
Raushan Kumar
|
|
|
|
|
What C# code have you got so far? If you post it we can take a look at it and make suggestions on how to fix it.
|
|
|
|
|
Hello,
This may be more of a PowerPoint issue that a C# one, but I thought I would try it this way since I cannot find a PowerPoint solution for this. I have written a C# application that calls PowerPoint slides from a menu. I would like to know if there is a way to randomly change the background of each PowerPoint slide that is called by selecting the graphic from a list of possibles. I cannot find a way to do this in PowerPoint alone and I wondered if there was a way to have C# do it for me; or perhaps if there is another solution? Thanks for your thoughts....Best, Pat
|
|
|
|
|
You are right. This is nothing at all to do with C#. I would suggest that a possible solution would be to use VBA to randomly choose the background and apply it.
|
|
|
|
|
Ok Pete....just did not know where to turn on this one so I took a shot. The good news is that your suggestion worked; I was able to modify some VBA code I found and make it work along the following lines (even though I have never written a word in VB before):
Public Sub ChangeBackgrounds()
'Global array to store pic names
Dim PictureList(1 To 10) As String
'List of pictures - in same directory as ppt:
PictureList(1) = "pic1.JPG"
PictureList(2) = "pic2.JPG"
PictureList(3) = "pic3.JPG"
PictureList(4) = "pic4.JPG"
PictureList(5) = "pic5.JPG"
PictureList(6) = "pic6.JPG"
PictureList(7) = "pic7.JPG"
PictureList(8) = "pic8.JPG"
PictureList(9) = "pic9.JPG"
PictureList(10) = "pic10.JPG"
'Define a slide
Dim mySlide As Slide
'Iterate through every slide in the presentation
For Each mySlide In ActivePresentation.Slides.Range
Dim PictureChoice
'Give us a random number between 1 and 10 as PictureChoice
PictureChoice = Int((20 * Rnd) + 1)
' Don't follow the master background style
mySlide.FollowMasterBackground = msoFalse
mySlide.Background.Fill.UserPicture (PictureList(PictureChoice)) 'Use our random number to choose a picture from the list
Next mySlide
End Sub
Thanks...Pat
|
|
|
|
|
good advice!
Craigslist Troll: litaly@comcast.net
"I have a theory that the truth is never told during the nine-to-five hours. "
— Hunter S. Thompson
|
|
|
|
|
Hi
I am having trouble building my database connection string, i have to read the server name, db, un, and password from an INI file (dont ask)
This is no problem, but im having trouble using these values to build my connection string
currently im getting the error
A field initializer cannont reference the nonstatic field, method or property
my knowledge of C# is basic to say the least, can anyone point me in the correct diretion or help at all?
thanks
Simon
Code Below
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;
using System.Runtime.InteropServices;
namespace WebService1
{
public class Service1 : System.Web.Services.WebService
{
string con;
string ini_path;
string tc_server="";
string tc_database="";
string tc_un="";
string tc_pwd="";
string tc_server_str="";
public Service1()
{
InitializeComponent();
ReadIniSettings();
con=CreateConnectionString();
}
SqlConnection myConnectionCP2 = new SqlConnection(con);
#region Component Designer generated code
private IContainer components = null;
private void InitializeComponent()
{
}
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
void ReadIniSettings()
{
ini_path="F:\\Web\\tr\\htdocs\\cpbl4\\";
tc_server = IniFile.ReadValue(ini_path,"TC","Server");
tc_database=IniFile.ReadValue(ini_path,"TC","Database");
tc_un=IniFile.ReadValue(ini_path,"TC","UN");
tc_pwd=IniFile.ReadValue(ini_path,"TC","Pwd");
}
string CreateConnectionString()
{
tc_server_str=SQLConn.CreateConnStr(tc_server,tc_un,tc_pwd,tc_database);
return tc_server_str;
}
}
public class IniFile
{
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,string key, string def, StringBuilder retVal,int size, string filePath);
public static void WriteValue(string path, string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, path);
}
public static string ReadValue(string path, string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, path);
return temp.ToString();
}
}
public class SQLConn
{
public static string CreateConnStr(string server, string un, string pwd, string db)
{
string connStr = "server="+server+";max pool size = 7500;uid="+un+";pwd="+pwd+";database="+db+";Connect Timeout=200;";
return connStr;
}
}
}
|
|
|
|
|
Probably this line: SqlConnection myConnectionCP2 = new SqlConnection(con);
You're trying to create the SQL connection in a field initializer... Not a good thing. That should be initialized inside the constructor (Or inside another function).
|
|
|
|
|