|
Yes Mycroft Holmes, in C# Application only..
Bajrang
|
|
|
|
|
You can do it through ADO
This is VBA code, but it should give you the idea
Sub ReturnUserRoster()
Dim cnn As New ADODB.Connection
Dim rst As ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Program Files\Microsoft " & _
"Office\Office\Samples\Northwind.mdb;"
Set rst = cnn.OpenSchema(adSchemaProviderSpecific _
, , JET_SCHEMA_USERROSTER)
Debug.Print rst.GetString
Set rst = Nothing
Set cnn = Nothing
End Sub
It's well known that if all the cat videos and porn disappeared from the internet there would be only one site left and it would be called whereareallthecatvideosandporn.com
|
|
|
|
|
I am hoping to get som advise from someone that has worked with audio programming in C#.
One of the thing I want to do is to play a section from a WAV file. E.g if the WAV file is 60 seconds long I want to be able to play e.g from 00:12 to 00:20 i.e 8 seconds. Any suggestions on how to do this? Any suggestions for good audio framework/libraries for C#?
Thanks
|
|
|
|
|
Why not search CodeProject, and examine the articles/code already here: example: searching on "c# audio .wav playback" => [^] ? Try varying the search terms. I predict you will find some resource here immediately useful to you; possibly, this: [^].
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
I am not positive on how to select the start/end position, but I know it is possible. I highly suggest using the NAudio library for this:
https://naudio.codeplex.com/[^]
NAudio is extremely robust and will provide you with everything you need. In the source code of the demo apps download, there are lots of examples on how to accomplish various tasks. I believe your answer is within one of those samples.
Hope that helps!
|
|
|
|
|
I remember I played around with playing MP3's a little bit with NAudio, here's a little bit of code that uses NAudio that may help you out...
IWavePlayer waveOutDevice;
WaveStream mainOutputStream;
WaveChannel32 volumeStream;
string fName = @"song.mp3";
private void Form1_Load(object sender, EventArgs e)
{
try
{
waveOutDevice = new WaveOut();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.GetType().ToString());
}
}
private void btnPlay_Click(object sender, EventArgs e)
{
try
{
if (waveOutDevice.PlaybackState.ToString() == "Playing")
{
return;
}
mainOutputStream = CreateInputStream(fName);
waveOutDevice.Init(mainOutputStream);
waveOutDevice.PlaybackStopped += new EventHandler<StoppedEventArgs>(waveOutDevice_PlaybackStopped);
waveOutDevice.Play();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.GetType().ToString());
}
}
private void waveOutDevice_PlaybackStopped(object sender, EventArgs e)
{
try
{
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.GetType().ToString());
}
}
private void btnStop_Click(object sender, EventArgs e)
{
try
{
if (waveOutDevice != null)
{
waveOutDevice.Stop();
}
if (mainOutputStream != null)
{
volumeStream.Close();
mainOutputStream.Close();
}
if (timerPosition.Enabled)
{
timerPosition.Enabled = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.GetType().ToString());
}
}
private WaveStream CreateInputStream(string fileName)
{
try
{
WaveChannel32 inputStream;
if (fileName.EndsWith(".mp3"))
{
WaveStream mp3Reader = new Mp3FileReader(fileName);
inputStream = new WaveChannel32(mp3Reader);
}
else
{
throw new InvalidOperationException("Unsupported extension");
}
volumeStream = inputStream;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.GetType().ToString());
}
return volumeStream;
}
private void CloseWaveOut()
{
try
{
if (waveOutDevice != null)
{
waveOutDevice.Stop();
}
if (mainOutputStream != null)
{
volumeStream.Close();
volumeStream = null;
mainOutputStream.Close();
mainOutputStream = null;
}
if (waveOutDevice != null)
{
waveOutDevice.Dispose();
waveOutDevice = null;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.GetType().ToString());
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
CloseWaveOut();
}
|
|
|
|
|
|
I have webservice and used memorycache to cache the lookups. My service is running on different machine. My client program accessing the that service is on other machine.
suppose my client calls the webservice and it gets data and add it to memory cache. Second time if client calls the webservice again, then does the cache will have the data or not (as my webservice and client are running on different machines)
|
|
|
|
|
The memory cache exists on the machine that the web service resides on.
|
|
|
|
|
Thank you Maxx, could you please eloborate your answer with respect to below scenario:
Service A: Gets some lookup data.
Where Service A is called from Service B.
Service A and Service B can be running on different machines.
So it looks this below
In service B, i have a class with method Say GetCityLookup()
GetCityLookup()
{
//Call service A to get city lookup
//add the response from service A in to the memorycache object.
}
So next time if GetCityLookup is called, will the data present in the cache or not.
|
|
|
|
|
I'm writing an application that performs a few independant tasks in the background. It's a console application.
My issue is that when the program is run, it starts to execute some of the stuff on the threads (processes maybe 1-2 lines of code) then quits before all the tasks are finished (I'm using the Task library, rather than standard Threads)
Rather than cramming all of my code into the Main() function, I'm separating them out into different functions for readability.
If I add a Console.ReadKey() at the end of the Main function, all the tasks run properly (they only take maybe 1-2 seconds, though over time that could change to several minutes, as it's performing file operations) and close properly when I hit a button.
However, once I'm finished with it, I don't want to have make the user do any inputs (it's going to be a "scheduled" task), in fact the window won't even be shown.
Part of my problem is that, by the nature of my program, I can't ever be completely sure of how many tasks are going to be running. The program pulls in a list of what needs to be done from an xml file.
Is there a safe way to perhaps create a list of tasks, then at the end of the Main() function, have it wait till all those tasks are complete before the program closes?
I tried using a
List<Task> but it didn't seem very safe, as I'd be building the array with other functions then doing a foreach() on the list and starting each task.
modified 31-Aug-13 7:33am.
|
|
|
|
|
Sorry, but I'm not downloading anything from an unknown URL.
But, If you're indeed using Tasks, there is always Task.WaitAll()[^] which is a blocking call that waits for all of the specified Tasks to complete before proceeding.
|
|
|
|
|
Problem with Task.WaitAll() is that it expects a fixed array (Task[]) of tasks, whereas the array could be anything from a single task to a dozen of them, and it's not known at run time.
The tasks are also created and start in a separate function from the Main() function.
I suppose I could (and might end up needing to) cram everything into Main() but I'm trying to avoid that as much as possible.
(Also, it's Pastebin, you're not downloading anything [besides overall web cache of the website], it's just a copy-paste of my code with syntax highlighting.)
|
|
|
|
|
Vouksh wrote: Problem with Task.WaitAll() is that it expects a fixed array (Task[]) of tasks,
whereas the array could be anything from a single task to a dozen of them, and
it's not known at run time.
Bullshit. Create a List<task> and add your Tasks to it. When you're done, call .ToArray() on the List and use you use that in Task.WaitAll.
Task.WaitAll can go into your code that creates your tasks. Since it's a blocking call, control will NOT return back to Main to end the application before the tasks are complete.
|
|
|
|
|
Thank you, I hadn't thought of using .ToArray() on a List. Forgot I could, honestly. I'll give it a try and, if it works, I'll mark this as solved.
Edit: Worked perfectly! Thank you very much!
|
|
|
|
|
Dave K. has answered your question, but I think you might get some benefit from a fantastic article by Keith Barrow (revised Aug. 30, 2013), "Await Tasks in C#4 using Iterators," about creating the functionality of C#5.0's await/async functionality for people using C#4.0.
It's one of the best written articles I have ever seen on CodeProject, and it contains a wealth of information that will give you "deep background" on threads, and asynchronous events [^].
good luck, Bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
modified 2-Sep-13 5:06am.
|
|
|
|
|
Thanks, I'll check it out.
|
|
|
|
|
BillWoodruff wrote:
article by Keith Barrow (revised Aug. 30, 2013), "Await Tasks in C#4 using Iterators,"
Thanks for the very kind words and article "plug" (promotion), my friend! The author is a different "Keith", though.
|
|
|
|
|
Hi all,
i am using code to disable a task in windows task scheduler.
here is my code
TaskService ts = new TaskService(@"\\" + domain + "", "" + user + "", "" + domain + "", "" + passwo + "", true);
ts = new TaskService();
Task t = ts.GetTask(Task);
if (t != null)
{
try
{
if (t.Enabled)
{
t.Enabled = false;
t.RegisterChanges();
}
}
finally
{
if (ts.Connected)
{
t.Stop();
ts.EndInit();
}
}
}
it is working fine but in the same application some more function is there when other function is running in between i am getting this error "safe handle has been closed".
i copied the stack trace and pasting here below:
" at System.Security.Principal.Win32.ImpersonateLoggedOnUser(SafeTokenHandle hToken)\r\n at System.Security.Principal.WindowsIdentity.SafeImpersonate(SafeTokenHandle userToken, WindowsIdentity wi, StackCrawlMark& stackMark)\r\n at System.Security.Principal.WindowsIdentity.Impersonate(StackCrawlMark& stackMark)\r\n at System.Security.SecurityContext.SetSecurityContext(SecurityContext sc, SecurityContext prevSecurityContext, StackCrawlMark& stackMark)\r\n at System.Threading.ExecutionContext.SetExecutionContext(ExecutionContext executionContext)\r\n at System.Threading.ExecutionContext.runTryCode(Object userData)\r\n at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)\r\n at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading._TimerCallback.PerformTimerCallback(Object state)"
please solve this problem it is irritating me too much.
Thanks,
Hello Everybody
|
|
|
|
|
So you've posted some code which does work, and an error message from some other code which doesn't work, but you haven't posted the code which doesn't work?
We can't read your mind or your screen; we're not the NSA. You'll need to post the code which is throwing the error before anyone can help you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi sir,
that error suddenly coming even it is not tracing by try catch block.
i pasted stack trace with my question. accept that i didn't get any specific line in which that error is coming but one thing if i am not using that code my application is working fine.
Thanks,
Hello Everybody
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
{
readThread = new Thread(new ThreadStart(Read));
port = new SerialPort();
port.BaudRate = 921600;
port.PortName = "COM16";
port.Parity = Parity.None;
port.DataBits = 8;
port.StopBits = StopBits.One;
port.ReadTimeout = 30000;
port.WriteTimeout = 30000;
port.DtrEnable = true;
port.RtsEnable = true;
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
port.Open();
}
private void buttonSend_Click(object sender, EventArgs e)
{
port.Write("AT+CUSD=1,\"*140*1#\",15" + System.Environment.NewLine);
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort spL = (SerialPort)sender;
byte[] buf = new byte[spL.BytesToRead];
spL.Read(buf, 0, buf.Length);
foreach (Byte b in buf)
{
message += b.ToString();
}
textBoxSMS.BeginInvoke((MethodInvoker)delegate()
{
textBoxSMS.Text += Encoding.ASCII.GetString(buf);
});
}
|
|
|
|
|
Wrong thread.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i have tired to search how to send USSD command on google.
i want to chek may balance from operator.
in every samples that i saw every body used commands like this:
"AT+CUSD=1,\"*140*1#\"\r\n";
it seams Tobe correct and i use somethings like this and i think it works.
i have a d-link gsm modem and when i send this command by it it make some noise on my speaker
from this i can find some thinks is happend
my modem have it's own windows application when i disconnected modem by my own application,i check it by modem's application and in USSD tab i can found the result of my commands that i sent by myself application.
then that command works fine but i 'm confuse what is happens when i sent my command it return me "OK" and do not return operator answer and how my modem's application can read that answer????????
i test these commands but can not get result and my modem just return somethings like this:
"AT+CUSD=1,\"*140*1#\"\r\n\OK\r\n" only.
1) "AT+CUSD=1,\"*140*1#\",15\r\n"
2) "AT+CUSD=1,\"*140*1#\",1\r\n"
3) "AT+CUSD=1,\"*140*1#\",15\r"
4) "AT+CUSD=1,\"*140*1#\",1\r"
5) "AT+CUSD=1,\"*140*1#\""
i think reading command's result maybe has difference command or i should set some config on my modem .
it is very interesting for me that my modem do not return error to me and always return OK.
|
|
|
|
|
You should read the documentation for your modem.
Veni, vidi, abiit domum
|
|
|
|
|