Task Vectors in In-Context Learning: Emergence, Formation, and Benefit